Concept
What is the alternative way to declare a structure in C?
ComputerScienceOne / Alternative Declarations
"In some examples and code bases you may find an alternative way of declaring a structure that looks like the following.\n\nstruct Student {\n\n...\n\n};\n\nThis syntax omits the keyword typedef and places the structure name at the beginning. The difference is a bit technical (the original syntax creates an anonymous structure with the Student identifier placed in the global namespace, while this declaration places the Student identifier in the structure namespace), but one of the consequences of using this type of declaration is that the Student identifier is not in the global scope, so to declare a variable of the type Student you need to further specify that it is a structure using the following syntax.\n\nstruct Student s;"
Related Ideas
- How should structure names and member variables be declared in C?ComputerScienceOne · Nested Structures
- How are structure instances declared and initialized?ComputerScienceOne · Declaration & Initialization
- How do you access members of a statically declared structure?ComputerScienceOne · Selection Operators
- How can one structure be composed of another structure?ComputerScienceOne · Declaration & Initialization
- How do you declare variables in C?ComputerScienceOne · Declaration & Assignment
- How do you access members through a pointer to a structure?ComputerScienceOne · Selection Operators
- How do you dynamically allocate and initialize a structure?ComputerScienceOne · Selection Operators
- How do you create and use an array of structures in C?ComputerScienceOne · Arrays of Structures