1. 程式人生 > >指標轉化為陣列

指標轉化為陣列

int a[3];
int* q = (int*)malloc(3 * sizeof(int));	//相當於q[3]

//動態分配一個數組,每個元素都是char* //char* buf[3]
int n = 3;
char** buf = (char**)malloc(n * sizeof(char*)); //相當於char* buf[3]
for (int i = 0; i < n; i++)
{
	buf[i] = (char*)malloc(30 * sizeof(char));
}