Structure Programming in C


Structure

                    Structure is the collection of the variable of different datatypes under same which is easy to handling. for example consider the sample of getting the employee name and no as input and display the same as output.

Syntax for the Structure

struct structure_name
{
   datatype variable_name1:
   datatype variable_name2;
   —————–
   —————–
   —————–
   datatype variable_name n;
}object_naem;

Sample Structure program for employee details

#include<stdio.h>
#include<conio.h>
struct employee 
{
   int emp_no;
   char emp_name[20];
}e;
void main()
{
   clrscr();
   printf(“enter employee name”);
   scanf(“%s”,&e.emp_name);
   printf(“Enter employee number”);
   scanf(“%d”,&e.emp_no);
   printf(“DETAILS OF THE EMPLOYEE”);
   printf(“****************************”);
   printf(“Name of the employee is %s :”,e.emp_name);
   printf(“Number of the employee is %d :”,e.emp_no);
   getch();
}
this is the sample program structure with pointer object will be the next post.
hope this will help you.
Advertisements

Tell us Your Suggestion

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s