I had a doubt in one of the usages of typedef. I want to know the meaning of this line:

typedef char Text[80];

What is the meaning of this line and what does it do?
Does it create an array of typedefs relating to char, or does it mean "Text means a string of size 80".

Thank you in advance! :D

3 Years
Discussion Span
Last Post by deceptikon

It means "Text means a character array of size 80", yes. There's no such thing as an array of typedefs because typedefs are a compile-time concept only - they're not something that can be stored in arrays.

The syntax of a typedef is basically the same as that of a variable definition (except for the keyword typedef in front obviously). The name of the typedef goes where the variable name would usually go and the type that that variable would have is the type that's being aliased. So since char Text[80]; would define a variable named Text that stores a character array of size 80, typedef char Text[80]; defines a typedef named Text that describes character arrays of size 80.


Adding to what sepp2k said, when you say Text foo, it's as if you said char foo[80]. A typedef represents a type, where the name of the typedef fits in the same place that the variable name would in an actual declaration. It's simpler and more consistent to keep the same declaration syntax rules.

Votes + Comments
Hmm... Thank you! :D
This question has already been answered. 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.