What are structures?
A structure is a collection of variables under a single name. These variables can be of different types, and each has a name which is used to select it from the structure. A structure is a convenient way of grouping several pieces of related information together.
A structure can be defined as a new named type, thus extending the number of available types. It can use other structures, arrays or pointers as some of its members, though this can get complicated unless you are careful.
Structure in breaf
A structure variable is a collection of other variables comprising different types.
What are pointers?
Ponters are variables which refer to the memory locations of other variables.
This is how a structure is defined.
example-12
struct cd
{
char name[20];
char description[40];
char category[12];
float cost;
int number;
};
Array structure
====================================================
#include<stdio.h>
#include<conio.h>
struct animal
{
int age;
char *name ;
char gender;
char *bPlace;
}a[100];
void main()
{
int i;
clrscr();
for(i=0;i<=10;i++)
{
printf("enter age");
scanf("%d",&a[i].age);
printf("enter name");
scanf("%d",&a[i].name);
printf("enter Birth Place");
scanf("%d",&a[i].bplace);
}
for(i=0;i<=10;i++)
{
printf("%d person\t",i+1);
printf("%d\n",a[i].age);
printf("%d\n",a[i].name);
printf("%d\n",a[i].bplace);
printf("========================\n");
}
getch();
}
No comments:
Post a Comment