STRUCTURE



What is Structure?

Structure in C is a user-defined data type used to bind two or more similar or different data types into a single type. It makes the program code organised and easy o read. Struct keyword is used to declare a structure




Syntax Input Output
#include<stdio.h>
void main()  
{
struct abc
{           
int a,b,c;
char d,e,f;
float g,h,i;      
}
struct abc p;           
p.a=10;
_____;
_____;
getch();
}
#include<stdio.h>
void main()
{
struct add
{
int a,b,c;
};
struct subtract
{
int d,e,f;
};
struct add add1;
struct subtract sub1;
struct subtract sub2;
struct add add2;
clrscr();
add1.a=15;
add1.b=23;
add1.c=add1.a+add1.b;
printf("\n%d\t+\t%d=\t%d",add1.a,add1.b,add1.c);
add2.a=19;
add2.b=26;
add2.c=add2.a+add2.b;
printf("\n%d\t+\t%d=\t%d",add2.a,add2.b,add2.c);
sub1.d=19;
sub1.e=26;
sub1.f=sub1.e-sub1.d;
printf("\n%d\t-\t%d=\t%d",sub1.e,sub1.d,sub1.f);
sub2.d=29;
sub2.e=56;
sub2.f=sub2.e-sub2.d;
printf("\n%d\t-\t%d=\t%d",sub2.e,sub2.d,sub2.f);
getch();
}