0% found this document useful (0 votes)
107 views8 pages

Pointers

The document contains C++ code that defines functions that manipulate variables passed as parameters in various ways, including pass by reference and pass by pointer. The main function calls the parameter manipulation functions and prints the values of variables before and after the calls to observe the effects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views8 pages

Pointers

The document contains C++ code that defines functions that manipulate variables passed as parameters in various ways, including pass by reference and pass by pointer. The main function calls the parameter manipulation functions and prints the values of variables before and after the calls to observe the effects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 8

#include <iostream>

using namespace std;

void parameterMystery(int& a, int& b, int c){

a+=c;

c++;

b--;

cout<<b<<" "<<a<<" "<<c<<endl;

int main(){

int w = 0;

int x = 1;

int y = 3;

int z = 7;

parameterMystery(w,w,z);

cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl;

N:2

#include <iostream>

using namespace std;

void v1v2p1p2(){

int v1 = 10;

int v2 = 25;
int* p1 = &v1;

int* p2 = &v2;

*p1 += *p2;

p2 = p1;

*p2 = *p1 + *p2;

cout << v1 << " "<< v2 << endl;

cout << *p1 << " "<< *p2 << endl;

int main(){

v1v2p1p2();

return 0;

N:3

/*

main's a variable is stored at address 0xaa00

main's b variable is stored at address 0xbb00

main's c variable is stored at address 0xcc00

main's d variable is stored at address 0xdd00

*/

#include <iostream>
using namespace std;

int parameterMystery1(int a, int &b, int*c){

b++;

a += *c;

cout<< b << " "<< *c <<" "<< a << " "<< c << endl;

c = &a;

return a-b;

int main(){

int a = 4;

int b = 8;

int c = -3;

int d;

d = parameterMystery1(a,b, &c);

cout<< a << " " << b << " " << c << " " << d << endl;

return 0;

N:4

/*

main's a variable is stored at address 0xaa00

main's b variable is stored at address 0xbb00

main's c variable is stored at address 0xcc00

main's d variable is stored at address 0xdd00


*/

#include <iostream>

using namespace std;

int parameterMystery4(int& x, int* y, int z){

x--;

z = z * 2;

cout << z << " " << x << " " << *y << endl;

(*y)++;

return x+z;

int main(){

int a = 2;

int b = 5;

int c = -3;

int d;

parameterMystery4(a, &b, c);

d = parameterMystery4(c, &a, b);

parameterMystery4(b, &d, a);

cout << a << " " << b << " " << c << " " << d << endl;

return 0;

}
N:5

/*

main's b variable is stored at address 0xbb00

main's d variable is stored at address 0xdd00

main's e variable is stored at address 0xee00

main's f variable is stored at address 0xff00

*/

#include <iostream>

using namespace std;

int parameterMystery5(int* d, int e, int& f){

f += 10;

*d = e + 2;

e--;

cout << e << " " << d << " " << *d << " " << f << endl;

return e+f;

int main(){

int b = 0;

int d = -1;

int e = 5;

int f = 2;

b = parameterMystery5(&d, e, f);
parameterMystery5(&f, d, e);

parameterMystery5(&b, f, d);

cout << d << " " << e << " " << f << " " << b <<endl;

cout << endl;

return 0;

N:6

/*

main's a variable is stored at address 0xaa00

main's b variable is stored at address 0xbb00

main's c variable is stored at address 0xcc00

main's d variable is stored at address 0xdd00

*/

#include <iostream>

using namespace std;

int parameterMystery11(int* a, int b , int& c){

c++;

*a += b;

cout << a << " "<< *a << " " << b << " " << c << endl;

return b + c;

int main(){

int a = 9;
int b = 5;

int c = 0;

int d = 2;

c = parameterMystery11(&b, d, a);

cout << a << " " << b << " " << c << " " << d <<endl;

return 0;

N:7

#include <iostream>

using namespace std;

int parameterMystery13(int* a, int &b, int* c){

*a = b + *c;

(*c)++;

cout << b << " " << *a << " " << *c << endl;

int main(){

int w = -9;

int x = 2;

int y = 5;

int z = 7;
parameterMystery13(&y, x,&w);

cout << w << " " << x << " " << y << " " << z << endl;

return 0;

You might also like