I hav开发者_JS百科e a question about typedef in c++
for example:
typedef const char* yes[5];
Does typedef gives a alternative name of const char*, so the alternative name of const char* is yes[5]
? what does yes[5]
here represents? and how to create two yes arrays and initializes one of the two?
No. This declares a type yes
which is an array of five const char *
.
See this link and type const char *yes[5];
inside the text area.
No, this makes yes
a new name for an array of 5 pointers to constant character data.
The way to think of it is the expression after typedef
looks like a declaration, and the name in the declaration is instead considered a name for the new type which is the type being declared.
So typedef int x;
makes x
be a new name for int
. This doesn't change with arrays.
精彩评论