Clouds
Home
Tutorial of C language
Computer Language
Introduction to C
Programming in C
Structure of C program
Variable in C
Datatypes in C
Token in C
Operator in C
Precedence of C Operator
Assignment Operator in C
Logical Operator in C
Bitwise Operator in C
Ternary Operator in C
C Input Output
Pointers in C
Storage Classes of C
Control Structure of C
C Decision Making Statement
C Looping Statement
C Jumping Statement
C Function
Function Call By Value
Function Call By Reference
C Input Output Function
C Structure
Array in C
Union in C

Structure

  • Structure is the collection of different data type of elements.
  • While array is the collection of same data type of the elements.
  • In Structure Struct keyword is use to create an user defined data type.

    Syntax:-

    				Struct 
    				{
    				Data type element1;
    				Datatype element2;
    				.
    				.
    				}
    
    				void  main()
    				{
    				Struct  variable1,variable2, variable3,.......;
    				}
    				

    Two operators are use in Structure to access the structural elements.

    Dot (.) operator

    Dot operator can be use in the following format. If user defined variable name is being used to accessed structural element.
  • Syntax:- variable-name . structure element=value/expression;

    Arrow (-->) operator

    Arrow operator can be used in the following format. When user defined variable reference (Address) is being use to accessed structural element.
  • Syntax:- Pointer -->structure element=value/expression;

    Example1:-

    				#include<stdio.h>
    				#include<conio.h>
    				struct employee
    				{
    				 	int eno;
    				  	float salary;
    				};
    				void main()
    				{
    				  	struct employee x;
    				  	clrscr();
    				  	printf("Enter the Employee No.:");
    				  	scanf("%d",&x.eno);
    				  	printf("Enter the Salary:");
    				  	scanf("%f",&x.salary);
    				  	printf("Employee No=%d\n",x.eno);
    				  	printf("Salary=%f",x.salary);
    				  	getch();
    				}
    				

    Example2:-

    				#include<stdio.h>
    				#include<conio.h>
    				struct employee
    				{
    				  	int eno;
    				  	float salary;
    				}x;
    				void main()
    				{
    				  	struct employee *p;
    				  	clrscr();
    				  	p=&x;
    				  	printf("Enter the Employee No.:");
    				  	scanf("%d",&p->eno);
    				  	printf("Enter the Salary:");
    				  	scanf("%f",&p->salary);
    				  	printf("Employee No=%d\n",p->eno);
    				  	printf("Salary=%f",p->salary);
    				  	getch();
    				}
    				

    Array in C >>
    Union in C >>
    Computer Language >>
    Introduction to C >>
    Programming in C >>


    Home Clouds