Structure
Is a data type to store a group of data with various of data type.Structure Declaration
1.struct name_structure {
dataType1 name_field1;
dataType2 name_field2;
…
} name_variable_structure ;
2.
struct name_structure name_variable_structure;
Accessing Structure
Element of a structure can be accessed using dot operator
struct mhs {
char nim[9];
char name[26];
float gpa;
};
int main (){
struct mhs lia;
gets(lia.name);
}
Structure Initialization
Syntax:
struct struct_name variable = {value_1, …, value_m};
struct employee info = {1,"B. Smith"};
Array of Structure
Structure data type can only contain one record. But real world problem needs group of records. So it's a structure inside a structure.
Example:
struct Dob{
int date, month, year;
};
struct Account {
int accountNo;
char accountType;
char name[31];
long credit;
struct Dob lastTrans;
};
//Array of structure
struct Account customer[100];
Union
A union is a special data type available in C that allows to store different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multiple-purpose.
Memory Allocation
Acquiring some memory space (RAM) managed by the OS to be used by the program.
Comments
Post a Comment