23 Structure-in-CPP
23 Structure-in-CPP
Topperworld.in
Structure
Syntax:
struct
{
// Declaration of the struct
}
Example:
#include <iostream>
using namespace std;
struct Rectangle
{
int width, height;
};
©Topperworld
C++ Programming
int main(void) {
struct Rectangle rec;
rec.width=8;
rec.height=5;
Output:
Example:
#include <iostream>
©Topperworld
C++ Programming
int main() {
// Declare a variable of the Person type
Person person1;
return 0;
}
Output:
Name: Alice
Age: 30
Gender: F
©Topperworld
C++ Programming
Structure Class
The instance of the structure is known as The instance of the class is known as
"Structure variable". "Object of the class".
©Topperworld