Write a program to demonstrate initilization of strucure

Updated:13/08/2023 by Computer Hope

Go Back



Want to learn how we can implement or initilization of strucure

A structure pointer's declaration is comparable to that of a structure variable. Thus, we are able to declare the variable and structure pointer both within and outside of the main() method. In C, we use the asterisk (*) symbol before the variable name to declare a pointer variable.


                //Write a program  to demonstrate initilization of strucure 
struct  student
{
int  sno=101,m=709;   
char sname[20]="sumit";
float  per=70.9;
};
void main()
{
struct student s1,s2;
printf("\n  %d  %d   %s   %f ", s2.sno , s2.m , s2.sname , s2.per );
printf("\n  %d  %d   %s   %f " , s1.sno , s1.m , s1.sname , s1.per );
}

              

Conclusion

In this article , struct mycar { char name[100]; float price; }; //mycar1 name as "xyz" //price as 987432.50 struct mycar car1 ={"xyz", 987432.50}