Structures:
One of the unique features of the C language is structures. They provide a method for packing together data of different types. A structure is a convenient tool for handling a group of logically related data items. It is a user defied data type with a template that serves to define its data properties.
Syntax:
<tag_name>
struct struct_name{
---------- //members of a structure
---------- //members of a structure
---------- //members of a structure
};
/*C Structures */
#include <stdio.h>
#include <stdlib.h>
int main()
{
struct sample
{
int x;
float y;
char z;
};
struct sample v1,v2;
v1.x=4;
v1.y=4.65;
v1.z='U';
printf("%d\n%.2f\n%c\n",v1.x,v1.y,v1.z);
printf("Enter an integer, float and a char\n");
scanf("%d%f%s",&v2.x,&v2.y,&v2.z);
printf("%d\n%.2f\n%c\n",v2.x,v2.y,v2.z);
return 0;
}
No comments:
Post a Comment