Advertisement
struct <name_of_structure>
{
1st element of structure;
2nd element of structure;
3rd element of structure;
...
};
struct <name_of_structure> <name_of_variables>;
Advertisement
/* An example of structure */
#include<stdio.h>
int main()
{
/* Declaring a structure */
struct bag
{
char gender_type;
int year_of_make;
float price;
};
/* Declaring a structure variable */
struct bag b1;
printf("Enter the gender type of the bag : ");
scanf("%c", &b1.gender_type);
printf("Enter the year of make of the bag :");
scanf("%d", &b1.year_of_make);
printf("Enter the price of the bag : ");
scanf("%f", &b1.price);
printf("The gender type of the bag : %c", b1.gender_type);
printf("\n");
printf("The year of make of the bag : %d", b1.year_of_make);
printf("\n");
printf("The price of the bag : : %.2f", b1.price);
return 0;
}
Enter the gender type of the bag : M
Enter the year of make of the bag :2018
Enter the price of the bag : 99.9
The gender type of the bag : M
The year of make of the bag : 2018
The price of the bag : : 99.90
struct bag
{
char gender_type;
int year_of_make;
float price;
};
struct bag b1;
printf("Enter the gender type of the bag : ");
scanf("%c", &b1.gender_type);
printf("The price of the bag : : %.2f", b1.price);
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement