structure with examples in Hindi

Structure in C in Hindi | C structure with examples in Hindi

C

Structure in c :- C Structure mei aap dusre predefined data types ko create kar sakte hai or ek record teyar kar sakte hai . Jese ki aap kisi person ke bare me ek uska name, address,age store karvana chahate hai to us person ke name se ek structure create kar sakte hai |or usme ye teen variables create kar sakte hai |

Aesa Karne se sari information ek hi jagah par hogi or ek hi name ke duvara access ki ja sakti hai |

Structure in C in Hindi

Contents

C Structure in Hindi ko samanjh ne ke liye ham examples ko dekhte hai.

Structure in c programming with examples

Defining a Structure 

Structure ko define karne ke liye struct keyword ka istemal kiya jata hai | is keyword ke bad structure ka unique name diya jata hai |iske bad curly braces mei variables create kiye jate hai or ending culry bracket ke bad semicolon lagaya jata hai |

struct struct_Name
{
     Structure member 1;
     structure member 2;
     …
     Structure member N; 
};
  • Struct ek keyword hai |
  • Struct ka data type koi sa bhi ho sakta hai |
  • Struct_Name matlab aap struct ka koi bhi name rakh sakte hai |
  • Structure member matlab aap usme kiya data rakhna chahte hai |
structure with examples in Hindi

Creating Structure Variables

  • With structure definition 
  • Without structure definition 

With structure definition

Jab aap structure definition ke sath hi us type ke variables create karte hai to ending semicolon se pahle aap variables ko comma se separate karke likh dete hai |

Syntax :

struct Student
{
   int rollno;
}t1,t2;

Without structure definition 

Syntax

struct Student
{
   int rollno;
};
struct Student t1,t2;

Accessing Structure Members 

Structure members ko aap 2 tarah se access kar sakte hai | ya to aap members ko values assign karvane ke liye ya fir unki values ko output ke rup me print karwane ke liye ab aap structure members ko access karte hai|

Jab bhi aap kisi bhi structure member ko access karte hai to aesa aap (.) dot operator duvara karte hai |

struct Student
{
   int rollno;
};
  int main()
{
    struct Student s1;
    printf("Enter The Student Roll No : ");
    scanf("%d",&si.rollno);
    
    printf("Student Roll no is : %d ", si.rollno);

    getch();
}   

Output :

Enter The Student Roll No : 21
Student Roll no is : 21

Nested Structures

Nested Structure means structure ke under ek or structure hai |

Example :

#include <stdio.h>
#include <conio.h>


/* Nested Structure */
struct dob
{
    int day;
    int month;
    int year;
}

/* main Structure */
struct Student
{
   char name[10];
   int rollno;
   float marks;
   struct dob d;
};
int main() 
{
   struct Student s;
   printf("Enter The Student Data : ");
   scanf("%s %d %f %d %d 
   %d",s.name,&s.rollno,&s.mark,&s.day,&s.month,&s.year);
   
   printf("Student Data\n ");
   printf("%s \n %d \n %f \n %d \n %d \n
   %d",s.name,s.rollno,s.mark,s.day,s.month,s.year);
   
getch();
}

Output:

Enter The Student Data : Danish 21 79 03 02 2002
Student Data
Danish
21
79
03
02
2002

C Array of Structure in Hindi

C Structure ko agar ek bar define kar diya jaye or hame 10 student ka data add karna hoto ko aap array ki help se kar sakte hai |

Example :

#include <stdio.h>
#include <conio.h>


/* main Structure */
struct Student
{
   char name[10];
   int rollno;
};

int main() 
{
   struct Student s[10];
   printf("Enter The Student Data : ");
   for(i=0;i<2;i++)
   {
       scanf("%s %d",s.name,&s.rollno);
    }

   
   printf("Student Data\n ");
   for(i=0;i<10;i++)
   { 
       printf("Name : %s \n Roll No :%d",s.name,s.rollno);
    }
   
getch();
}

Output:

Enter The Student Data : Danish 21 s2 15 s3 16 s4 17 s5 18 s6 19 s7 20 s8 21 
                         s9 22 s10 23
Student Data
Name : Danish
Roll No :21
Name : s2
Roll No :15
Name : s3
Roll No : 16
Name : s4
Roll No : 17
Name : s5
Roll No :18 
Name : s6
Roll No : 19
Name : s7
Roll No : 20
Name : s8
Roll No : 21
Name : s9
Roll No : 22
Name : s10
Roll No : 23

Structure as Function Argument

Structure ko aap kisi function mei argument ke rup mei bhi pass kar sakte hai | iske liye aapko kisi prkar ke special operator ki jaruart nhi hoti hai |

Example :

#include<stdio.h>
 

/* Structure Person declaration */
struct Person
{
    int Id;
    int Phone;
};

void printPerson(struct Person p1);

int main()
{
    struct Person p1;

    p1.Id = 101;
    p1.Phone = 237434839;

    /* Passing variable of structure Person */
    printPerson(p1);

    return 0;
}

void printPerson(struct Person p1)
{
    printf(“Name is : %dn”,p1.Id);
    printf(“Phone number is %dn”,p1.Phone);
}

Output:

Id : 101
Phone : 237434839

Pointer to Structure

Structure variables ke pointers bhi create kiye ja sakte hai | ye usi tarah create kiye jate hai jese ki aap kisi normal varable ke pointers create karte hai |

Example :

#include<stdio.h>
 

/* Employee structure declaration */
struct Employee
{
    int Id;
    int Phone;
};

int main()
{

   /* Creating variable of Employee structure */
   struct Employee e1;
 
   struct Employee *emp;

   emp = &e1;

   emp->Id=101;
   emp->Phone = 237434839;

   printf(“Employee Id : %dn”,emp->Id);
   printf(“Employee Phone : %dn”,emp->Phone);

   return 0;
}

Output :

Employee Id : 101
Employee Phone : 2374334839

Structure in c Hindi

Dosto mujhe ummed hai ki aap Structure in c Hindi  ko acchi tarah se samanj gye honge agar aap ko ye post acchi lage to mere is website ko jarur follow kre or ha agar aap video bhi dekhna chahte hai to aap mere channel ko bhi subscribe kar sakte hai. channel ka link aapko home page par mil jayega |

Leave a Reply

Your email address will not be published. Required fields are marked *