In this part you will learn:
1. C syntax
2. Structure variable
3. Structure declaration
4. Structure accessing
5. Showing output
Structure is a user-defined data type in C which allows you to combine different data types to store a particular type of record. Structure helps to construct a complex data type in a more meaningful way. Structure helps when you have to store a collection of data of many similar things or people etc.
It is somewhat similar to an array. The difference is that an array is used to store a collection of similar type of data while structure can store collection of any type.
Structure are best used to represent a record. If you want to store a record of hundred student you will need to define hundred variables to store the name and similarly hundred variables for each type of data you need to enter in the record.
This is where structures come in handy. In this program we will make a structure of student that will store the name of the student, the age of the student and the gpa.
Open Dev C++ then File > new > source file and start writing the code below.
- struct Student
- char name;
- int age;
- float gpa;
- int main()
- Student s;
- int i,j;
- for(i=0; i<3;i++)
- printf("Enter the name of the student %d: ",i+1);
- scanf(" %s",&s[i].name);
- printf("Enter the age of student %d:",i+1);
- printf("Enter the GPA of student %d:",i+1);
- float maxgpa;
- int l;
- else if(maxgpa<s[l].gpa)
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.