In this article you will Learn about Structure in c++ Programming language
What is Structure in C++
A structure is can be used to store together elements of different data types . In c++ , a Structure is a user-defined data types . The Structure creates a data type for grouping items of different data types under a single data type .
For Example :
You have open a store and give all information about books title , author, subject , etc. so you create a variable like title, author , subject and book_id to store data seprately .
When we use Structure in C++
In some cases you have to use the Structure
- Use a Struct when you need to Store a Elements of different types under one-data type .
- C++ Structure are value type rather than being a refrence type . Use a struct if you don't intend your data after creation.
C++ Struct Initialization
To create a c++ Structure , we use the struct keyword use the following identifier. Here is the syntax for creating the structure .
Syntax :
Struct Struct_name{
// Struct members
}
In this above syntax we have use the structure keyword.
For Example :
#include <iostream> using namespace std; struct book { char title[50]; char author[50]; }; int main(void) { struct book b; b.title = mathmatics; b.author = sudhir kumar ; cout << "Title of the book : " << b.title << endl; cout << "author of the book: " << b.author << endl; return 0; }
Title of the Book : mathmatics
author of the book : sudhir kumar
If you have more knowledge about this topic so You can Share with me . abuzar.abuzar.mohd325@gmail.com
Share to Your Friends.
SUGGEST CONTENT :
0 Comments
Do not Comment and any spam text