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 can one structure be composed of another structure?ComputerScienceOne · Declaration & Initialization
- How can structures be dynamically allocated?ComputerScienceOne · Declaration & Initialization
- How do you create and use an array of structures in C?ComputerScienceOne · Arrays of Structures
- What topics are covered in this section?ComputerScienceOne · Nested Structures . . . . . . . . . . . . . . . . . . . . . . . . . . .