



































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




































Data Types C programming language which has the abilityto divide the data into different types. The typeof a variable determine the what kind of values itmay take on. The various data types are• Simple Data type
^ Integer, Real, Void, Char
Array, Strings
Enum, Structures, Unions
Defining of Structure A structure has to defined, before it can used.The syntax of defining a structure isstruct <struct_name>{ <data_type> <variable_name>;<data_type> <variable_name>;……..<data_type> <variable_name>;};
Example of Structure The structure of Employee is declared asstruct employee{ int emp_id;char name[20];float salary;char address[50];int dept_no;int age;};
Declaring a Structure Variable A structure has to declared, after the body ofstructure has defined. The syntax of declaring astructure isstruct <struct_name> <variable_name>;The example to declare the variable for definedstructure “employee”struct employee e1;Here e1 variable contains 6 members that aredefined in structure.
Initializing a Structure Members The members of individual structure variable isinitialize one by one or in a single statement. Theexample to initialize a structure variable is1) struct employee e1 = {1, “Hemant”,12000, “3vikas colony new delhi”,10, 35);2) e1.emp_id=1;^
e1.dept_no= e1.name=“Hemant”;
e1.age=35; e1.salary=12000;e1.address=“3 vikas colony new delhi”;
Structure Assignment The value of one structure variable is assignedto another variable^ of
same^ type
using assignment^ statement.
If^ the^ e1^ and
e2^ are structure variables of type employee then thestatement
e1 = e2;assign value of structure variable e2 to e1. The value of each member of e2 is assignedto corresponding members of e1.
Program to implement the Structure #include <stdio.h>#include <conio.h>struct employee{ int emp_id;char name[20];float salary;char address[50];int dept_no;int age;};
Program to implement the Structure scanf(“%d”,&e1.age);printf (“Enter the employee id of employee”);scanf(“%d”,&e2.emp_id);printf (“Enter the name of employee”);scanf(“%s”,e2.name);printf (“Enter the salary of employee”);scanf(“%f”,&e2.salary);printf (“Enter the address of employee”);scanf(“%s”,e2.address);printf (“Enter the department of employee”);scanf(“%d”,&e2.dept_no);printf (“Enter the age of employee”);scanf(“%d”,&e2.age);
Program to implement the Structure printf (“The employee id of employee is : %d”,e1.emp_id);printf (“The name of employee is : %s”,e1.name);printf (“The salary of employee is : %f”,e1.salary);printf (“The address of employee is : %s”,e1.address);printf (“The department of employee is : %d”,e1.dept_no);printf (“The age of employee is : %d”,e1.age);
Program to implement the Array of Structure^ #include <stdio.h>#include <conio.h>struct employee{ int emp_id;char name[20];float salary;char address[50];int dept_no;int age;};
Program to implement the Array of Structure^ void main ( ){ struct employee e1[5];int i;for (i=1; i<=100; i++){ printf (“Enter the employee id of employee”);scanf (“%d”,&e[i].emp_id);printf (“Enter the name of employee”);scanf (“%s”,e[i].name);printf (“Enter the salary of employee”);scanf (“%f”,&e[i].salary);