Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `const char* yes[5]` represents in this line of code?

Tags:

c++

typedef

I have 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?

like image 301
cong Avatar asked May 06 '11 14:05

cong


2 Answers

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.

like image 160
Benoit Avatar answered Oct 08 '22 15:10

Benoit


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.

like image 36
unwind Avatar answered Oct 08 '22 16:10

unwind