What is Structure in C++ in Hindi - C++ में Structure क्या है
Structure संबन्धित अन्य महत्पूर्ण बाते
किया जाता है
Declaration of Structure in C++ in Hindi
Syntax:
struct structure_name {
dataType member_name1;
dataType member_name2;
............
............
};
struct:
ऊपर Syntax में 'struct' एक keyword है जिसका प्रयोग एक Structute को Define करने में किया जाता है
structure_name:
यह structure को दिया गया नाम है
curly braces'{}' के अंदर Variable के members की उसके Data type के साथ सूची है
Structure को Declare करने के कुछ Examples
Example 1:
struct Employee
{
EID int;
string name;
double salary;
};
ऊपर के कोड मे एक structure `Employee` नाम से Define किया गया है जो अपने में 3 members EID, name, और salary को रखता है।
Example 2:
struct Student
{
int SID
string name;
int age;
};
Access Structure Members in C++ in Hindi - C++ में Structure member को Access करना
Dot (.) operator का Use करके Structure के members को Access करना
#include<iostream> #include<cstring>
using namespace std; // Define the structure struct student { int sid; char name[30]; int age; }; int main() { // Declare a variable of type struct employee struct student s1, s2 ; //Storing the first student's Information s1.sid = 10; strcpy(s1.name, "Rahul"); s1.age = 25; //Storing the second student's Informations2.sid = 12;
strcpy(s2.name, "Aman");
s2.age = 30;// Printing the first student's Information
cout<<"First student's ID : "<<s1.sid<<endl;
cout<<"First student's name: "<<s1.name<<endl;
cout<<"First student's age: "<<s1.age<<endl<<endl;
// Printing the second student's Informationcout<<"Second student's ID : "<< s2.sid<<endl;
cout<<"Second student's name: "<<s2.name<<endl;
cout<<"Second student's age: "<<s2.age<<endl;
return 0;
}
Second student's name: Aman
Second student's age: 30
Pointers का Use करके
#include<iostream>
#include<cstring>
using namespace std;
// Define the structure
struct employee
{
int id;
char name[30];
double salary;
};
int main()
{
struct employee e1, e2;
struct employee *ptrE1 = &e1;
struct employee *ptrE2 = &e2;
// Storing information for the first employee
ptrE1->id = 10;
strcpy(ptrE1->name, "Amit Kumar");
ptrE1->salary = 40000;
// Storing information for the second employee
ptrE2->id = 11;
strcpy(ptrE2->name, "Yash Kumar");
ptrE2->salary = 35000;
// Printing information for the first employee
cout<<"Ist Employee's ID: "<<ptrE1->id<<endl;
cout<<"Ist Employee's Name: "<<ptrE1->name<<endl;
cout<<"Ist Employee's Salary: "<<ptrE1->salary<<endl<<endl;
// Printing information for the second employeecout<<"IInd Employee's ID: "<<ptrE2->id<<endl;
cout<<"IInd Employee's Name: "<<ptrE2->name<<endl;
cout<<"IInd Employee's Salary: "<<ptrE2->salary<<endl;return 0;}
Array of Structure in C++ in Hindi
#include<iostream> #include<cstring> using namespace std; struct student { int id; char name[30]; int age; }; int main() { struct student Stu[4]; Stu[0].id =101; strcpy(Stu[0].name,"Rahul Sinha"); Stu[0].age = 30;
// Initialize the second student Stu[1].id = 102; strcpy(Stu[1].name, "Sunil Kumar"); Stu[1].age = 25;
// Initialize the third student
Stu[2].id = 104;
strcpy(Stu[2].name, "Aman Sahu");
Stu[2].age =35;
// Initialize the fourth student
Stu[3].id = 105;
strcpy(Stu[3].name, "Yash Chopra");
Stu[3].age = 36;
// Printing information for all students
for (int i = 0; i < 4; i++)
{
cout<<"Student's ID: "<<Stu[i].id<<endl;
cout<<"Student's Name: "<<Stu[i].name<<endl;
cout<<"Student's Age: "<<Stu[i]. age<<endl;
}
return 0;
}
Output:
Structure Pointer in C++ in Hindi
#include<iostream>
#include<cstring>
using namespace std;
struct Student
{
int sid;
string name;
int age;
};
int main()
{
// Declaration of a structure variable
Student s1;
// Initialize structure members
s1.sid = 101;
s1.name = "Rohit Kumar";
s1.age = 25;
// Creating a pointer to the structure
Student *ptrStudent = &s1;
// Accessing to structure members using pointer
cout << "SID: " << ptrStudent->sid << endl;
cout << "Name: " << ptrStudent->name << endl;
cout << "Age: " << ptrStudent->age << endl;
return 0;
}
Name: Rohit Kumar
Age: 25
Difference between Structure and Class in C++ in Hindi
Related Posts
> C++ क्या है? उसके इतिहास, गुण, उपयोग, फायदे और नुकसान
> Basic structure of C++ Program
> C++ में Tokens क्या है? और उसके प्रकार
> C++ Variables क्या है?, उसके प्रकार, उसे कैसे Declare, Define करते हैं
> C++ में Constants क्या है? उसके प्रकारों की संपूर्ण जानकारी
> C++ में Basic Input और Output (cin,cout,cerr) की जानकारी
> Data type in C++ की संपूर्ण जानकारी
> C+ में Operators और उसके प्रकार जानें Practical सहित
> C++ में Conditional और उसके प्रकारों को जानें Practical सहित
> C++ में Looping statements और उसके प्रकार Practical सहित
> C++ में Jump Statements और उसके प्रकारों की संपूर्ण जानकारी Practical सहित
> C++ में Array क्या है? और उसके प्रकारों की जानकारी Practical सहित
> C++ में Function क्या है उसके प्रकार, उपयोग प्रोग्राम सहित
> OOPs Concepts in C++ in Hindi- C++ में OOPs के बारे में
> Oops के फायदे और नुकसान की जानकारी
> C++ में Class और Object की सम्पूर्ण जनकारी
> C++ में Array of Objects क्या है?
> C++ में Pointers, Pointer to an objects, Pointer to an Array की संपूर्ण जानकारी हिंदी में।
> C++ में Passing objects क्या है
> C++ में Reference और Type Casting की संपूर्ण जानकारी
> C++ में Access specifier की संपूर्ण जानकारी
> C++ में Static Data Members और Member Functions के बारे में Practical सहित
> C++ में Memory allocation और Memory management operators (new और delete) Practical सहित
> Friend Function in C++ in Hindi
> Friend Class in C++ in Hindi Practical सहित
> Inline function in C++ in Hindi
> Function Overloading in C++ in Hindi Practical सहित
> Operator Overloading in C++ in Hindi Practical सहित
> C++ में Constructor क्या है और उसके प्रकारों की संपूर्ण जानकारी
> C++ में Destructor क्या है ?उसकी संपूर्ण जानकारी
> C++ मे Inheritance क्या है उसके प्रकारों को जानें प्रोग्राम सहित
> C++ में Polymorphism क्या है? और उसके प्रकारों को जानें
> C++ में Virtual function की संपूर्ण जानकारी
> C++ में File handling की संपूर्ण जानकारी
> C++ में Exception handling की संपूर्ण जानकारी
0 टिप्पणियाँ