Structures are used to represent a record, suppose you want to keep track of your books in a library.
Object-oriented Programming in 7 minutes - Mosh
To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member, for your program.
The structure tag is optional and each member definition is a normal variable definition, such as int i; or float f; or any other valid variable definition. At the end of the structure's definition, before the final semicolon, you can specify one or more structure variables but it is optional.
To access any member of a structure, we use the member access operator. The member access operator is coded as a period between the structure variable name and the structure member that we wish to access. You would use struct keyword to define variables of structure type.
You can pass a structure as a function argument in very similar way as you pass any other variable or pointer. Now, you can store the address of a structure variable in the above defined pointer variable. There is an easier way to define structs or you could "alias" types you create.
Now, you can use Books directly to define variables of Books type without using struct keyword. Previous Page.
Next Page. Live Demo.
Previous Page Print Page.