Friday 23 September 2011

Structure

Structure is a collection of dissimilar data type element.
we can creat a structure using a "struct" key-word.
systax:
      struct SN
      {
      dt v1; 
      dt v2;
      dt v3;
      } SV;
or 
     struct SN
     {
     dt v1;
     dt v2;
     dt v3;
     };
    struct SN SV;
or 
   struct 
    {
   dt v1;
   dt v2;
   dt v3;
   }SV;
    
To Access- 
    SV.SN;
ex: 
   struct record 
   {
   char n[20];
   int age;
   char c[30];
   }e;
  
--->e.n,e.age,e.c;
Question 1: write a program to enter the name ,age and city of a employ and print them?
Answer:
#include<stdio.h>
#include<conio.h>
void main()
{
struct record
{
char n[20];
 int age;
char c[20];
}e;
clrscr();
printf("enter the name");
gets(e.n); // scanf("%s",&e.n);
printf("\n enter the age");
scanf("%d",&e.age);
printf("\n enter the city");
scanf("%s",&e.c);
printf("\n name=%s",e.n);
printf("\n Age=%d",e.age);
printf("\n city=%s",e.c);
getch();
}
  

   
  


       
  
 
  

No comments:

Post a Comment