Structure in C++
In C++, structures
are user-defined data types used to group together different variables with
different data types under a single name in different memory location. They
provide a way to organize related data and can be used to represent real-world
entities or concepts.
By using period or
dot (.) operator we can access the member of structure. Syntax to access the
members of structure are:-
Structure_variable .member
Program to access of member
of structure
#include<iostream>
using namespace std;
struct st
{
int a,b,c;
};
int main()
{
struct st stu;
cout<<”a=”;
cin>>stu.a;
cout<<”b=”;
cin>>stu.b;
stu.c=stu.a+stu.b;
cout<<”sum=”<<stu.c;
return 0;
}
Output
a=10
b=10
sum=20
0 Comments