1
2#include <bits/stdc++.h>
3#include <iostream>
4
5#define ll long long
6
7using namespace std;
8
9struct student{
10 int roll;
11 string name;
12 int age;
13
14 void studentDetails(){
15 cout<<"Name is "<<name<<" Age is "<<age<<" roll no is "<<roll<<endl;
16 }
17};
18
19
20int main(){
21
22 student sumant;
23 sumant.roll = 30;
24 sumant.name = "Sumant Tirkey";
25 sumant.age = 18;
26
27 sumant.studentDetails();
28 cout<<endl;
29
30 return 0;
31}
1struct foo {
2 int bar;
3 foo() : bar(3) {} //look, a constructor
4 int getBar()
5 {
6 return bar;
7 }
8};
9
10foo f;
11int y = f.getBar(); // y is 3