C++ Program using structure and function


In this program, You will learn how to implement structure and function in C++.


struct struct_name{ };

void display(){ }


Example: How to implement structure and function in C++

Run it Now
#include<iostream>
using namespace std;

struct Test {
    int x, y;
};

void display(Test t) {
    cout << "The x value is :" << t.x;
    cout << "\nThe y value is :" << t.y;
}

int main() {

    struct Test t;

    t.x = 10;
    t.y = 20;

    display(t);

    return 0;
}

Output:

The x value is :10
The y value is :20