@EggGump
2018-08-27T17:22:20.000000Z
字数 615
阅读 574
python
python3.6.5
#定义数组
array = c_int*10
myArray = array(1,2,3,4,5)
for i in myArray:
print(i)
#二维数组,接前面
array2 = array*2
myArray2 = array2(myArray,myArray)
#此时,该二维数组里有两个一维长度为10的一维数组
下面我们来把python里面的数组传到c里面再输出,这里是例子截图
test.c
test.py
编译:
运行截图
再来一个有返回值的
int array2(int a[][10]){
int i = 0;
for (i = 0; i < 2; i ++){
int j = 0;
for(j = 0; j < 10; j ++){
printf("%d,",a[i][j]) ;
}
printf("\n");
}
return i ;
}
from ctypes import *
#load the shared object file
adder = CDLL('./test.so')
array = c_int * 10
myArray = array(1,2,3,4,5,6,7,8,9,10)
array2 = array*2
myArray2 = array2(myArray,myArray)
result = adder.array2(myArray2)
print("python:",result)
结果截图: