Structure:
-It is collection of different value having different data types.
Array vs Structure:
Array is a collection of same data type while structure have capability to store different data type.
Syntax-
struct name
{
data types;
};
-Here struct is the keyword that are use to initialize the structure.
Example-
struct Mydata
{
char name[20];
int age;
float salary;
};
Store and access data in structure:
program-
#include< stdio.h>
struct r4r
{
int x;
char ch;
};
int main()
{
//store value with object.
struct r4r obj;
// Accessing members of point p1
obj.x=10;
obj.ch="a";
printf ("%d %d", obj.x, obj.y);
return 0;
}
10 a