Advertisement

C++ Program using structure and function


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


struct struct_name{ 
      //statement
};

void display(){ 
    //statement
}

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

#include<iostream>
using namespace std;

struct Test {
    int x, y;
};

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

int main() {

    struct Test t;

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

    display(t);

    return 0;
}

Output:

x value is:10
y value is:20