| C Tutorial | Data types in C | |||
|
Data types in C
|
C has the usual facilities for grouping things together to form composite types-- arrays and records (which are called "structures"). The following definition declares a type called "struct fraction" that has two integer sub fields named "numerator" and "denominator". If you forget the semicolon it tends to produce a syntax error in whatever thing follows the struct declaration.
struct fraction { int numerator; int denominator; }; // Don't forget the semicolon!
This declaration introduces the type struct fraction (both words are required) as a new type. C uses the period (.) to access the fields in a record. You can copy two records of the same type using a single assignment statement, however == does not work on structs. struct fraction f1, f2; // declare two fractions f1.numerator = 22; f1.denominator = 7;
f2 = f1; // this copies over the whole struct
Want To Know more with Video ???
|
|