#include <iostream>
#include "stdlib.h"

using namespace std;

struct var{
int a;
int b;
int result;

};

void adD(var&);

int main()
{
int a;
int b;
cout<<"please ente the value a ====  "<<endl;
cin>>a;
cout<<"please ente the value b ====  "<<endl;
cin>>b;
var v1;
adD(v1);

 system("cls");
 cout<<"the value of result ==  "<<v1.result<<endl;
 return 0;
}
void adD(var& v1){

v1.result = (v1.a)+(v1.b);

}

I don't know what you are asking for but you need to cin >> v.a >> v.b [\i]. Make sure you define var v before using it in cin

First of all you need to put your code in the code tags, second of all, what's the problem you are having?

Yes, that's right what firstPerson is saying, you are adding variables that have not been given values, v1.a and v1.b are being added but have not been assigned values.

Yes structure can be passed by reference. As firstPerson said you must take input in structure or you can initialize your structure with values a and b.

v1.a = a;
v1.b = b;

Write above code after declaration of var v1 and before calling function adD(v1);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.