What is the structure?

C Programming Language >   Structure in C Language >   Structure in C  

Long Question

586


Answer:

  • The structure is a user-defined data type that allows storing multiple types of data in a single unit. It occupies the sum of the memory of all members.
  • The structure members can be accessed only through structure variables.
  • Structure variables accessing the same structure but the memory allocated for each variable will be different.
Syntax of structure

struct structure_name  
{  
  Member_variable1;  
 Member_variable2  
.  
.  
}[structure variables];  


Let's see a simple example.


#include <stdio.h>  
struct student  
{  
    char name[10];       // structure members declaration.  
    int age;  
}s1;      //structure variable  
int main()  
{  
    printf("Enter the name");  
    scanf("%s",s1.name);  
    printf("\n");  
    printf("Enter the age");  
    scanf("%d",&s1.age);  
    printf("\n");  
    printf("Name and age of a student: %s,%d",s1.name,s1.age);  
    return 0;  
}  

Output:
Enter the name shikha
Enter the age 26
Name and age of a student: shikha,26  


This Particular section is dedicated to Question & Answer only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.