Struct Example in C++


Description:

In C++, a structure is the same as a class except for a few differences. The most important of them is security. A Structure is not secure and cannot hide its implementation details from the end user while a class is secure and can hide its programming and designing details

Example Program:

Here is the simple program using struct in C++.

Source Code

#include<iostream>
using namespace std;
struct test
{
    int x;  //Data Member
    int y;

    void display()//Data Function
    {
        cout<<"X value is : "<<x<<endl;
        cout<<"Y value is : "<<y<<endl;
    }
};

int main()
{
    test o;
    o.x=10;
    o.y=20;
    o.display();
    return 0;
}
To download raw file Click Here

Output

X value is : 10
Y value is : 20

Basic Programs


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes