Initializing Structure Variable in C
- Memory is not allocated for Un-initialized Variable.
- Let us discuss very familiar example of structure student , We can initialize structure variable in different ways -
Way 1 : Declare and Initialize
struct student
{
char name[20];
int roll;
float marks;
}std1 = {"Pritesh",67,78.3);
Way 2 : Declaring and Initializing Multiple Variables
struct student
{
char name[20];
int roll;
float marks;
}
std1 = {"Pritesh",67,78.3);
std2 = {"Don",62,71.3);
Way 3 : Initializing Single member
struct student
{
int mark1;
int mark2;
int mark3;
}sub1={67};Though there are three members of structure,only one is initialized , Then remaining two members are initialized with Zero Way 4 : Initializing inside main
struct student
{
int mark1;
int mark2;
int mark3;
};
void main()
{
struct student s1 = {89,54,65};
- - - - --
- - - - --
- - - - --
};
Note : Structure array will be covered in later chapters.
Bookmark & Share



0 Comments:
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email