0

Hi
how is the typedef for monthTable working while the statement at line 6 not working?

#include <stdio.h>

typedef const char * monthTable[3];

// uncommenting the following generates compile error
//int[5] A;

int main()
{
	monthTable t1,t2={"Jan","Feb","Mar"};
	int i=0;
	for(i=0;i<3;i++)
	{
		printf("%s\n",t2[i]);
	}
	return 1;
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Narue
0

>how is the typedef for monthTable working while the statement at line 6 not working?
The typedef is syntactically and semantically correct, while line 6 isn't valid C. Do you know how to declare an array in C? It's pretty easy given your code, just take the typedef and remove the typedef keyword. That turns the line into the declaration of an array called monthTable. Now compare that with line 6 and look for differences.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.