user239353
10
Q:

function in struct c++

struct Person
{
    char name[50];
    int age;
    float salary;
};
2
struct foo {
  int bar;
  foo() : bar(3) {}   //look, a constructor
  int getBar() 
  { 
    return bar; 
  }
};

foo f;
int y = f.getBar(); // y is 3
0

New to Communities?

Join the community