C Programming/Structure Datatype
- A structure in C is a collection of items of different types. Structure may be consider as a record like Pascal or a class in Java without methods.
- Structures, or structs, are very useful in creating data structures larger and more complex
- Simply group various built-in data types into a structure.
- Object concepts was derived from Structure concept.
//main.c
#include <stdio.h>
struct student {
char firstName[20];
char lastName[20];
char SSN[10];
float gpa;
};
int main(void)
{
struct student student_a;
strcpy(student_a.firstName, "Deo");
strcpy(student_a.lastName, "Dum");
strcpy(student_a.SSN, "2333234" );
student_a.gpa = 2009.20;
printf( "First Name: %s\n", student_a.firstName );
printf( "Last Name : %s\n", student_a.lastName );
printf( "SNN : %s\n", student_a.SSN );
printf( "GPA : %f\n", student_a.gpa );
return 0;
}