简体   繁体   中英

Difference between char* x and char* x[80]?

char* xchar* x[80]之间有什么区别?

char* x is a pointer to char .

char* x[80] is an array of 80 elements, the elements are pointers to char .

char * x is a pointer to a char.

Means you can do operations like:-

char * x = "Hello World";

char * x[80] is an array of 80 elements, all of which are pointing to chars. Means you can do something like this:-

x[0] = "This is number 1";
x[1] = "This is number 2";
x[2] = "Well it goes on!";

I hope it makes even more clear.

char a :: a is a variable of type char which can store a character.

char a[10] :: 'a' is an array of 10 variables of type 'char' which can store a character.

Similarly,

char* x :: x is a variable of type char* (Pointer to a char) which can point to another variable of type char .

char* x[80] :: x is an array of 80 variables of type char* (Pointer to a char) which can point to another variable of type char .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM