wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C++ References

Total questions: 12

Worksheet time: 36mins

Name
Class
Date
1.

In C++ a variable that has an & appended is storing a(n):

a)

value

b)

address

c)

integer

d)

string

2.

The "&" symbol is called a(n):

a)

sandpaper

b)

ampersand

c)

percentage sign

d)

andthisthat

3.

I have a variable int a = 2;


then a variable int& b = a;


What happens if I change the value of b

a)

Nothing

b)

a changes as well

c)

b gets bigger

d)

a disappears

4.

Which of these looks like a possible output


int variable = 5;


cout<<&variable;

a)

5

b)

0x7ffc8d64e404

c)

&5

d)

this would throw an error

5.

If the address of b is at 0x7ff.

What would the following code output?


int b = 160;

int &a = b;

int &c = a;


cout<<a <<endl;

cout<<&c;

a)

160

160

b)

0x7ff

160

c)

160

0x7ff

d)

0x7ff

0x7ff

6.

Given the function


int var(int& x){

x+= 10;

return 0;

};


What will this code output?


int main(){


int b = 160;


var(b);


cout<<b <<endl;


}

a)

160 160

b)

170

c)

b

d)

22xff

7.

Given the function


int var(int& a){

a*= 2;

return 0;

};


What will this code output?


int main(){


int b = 160;

int a = b - 60;


var(a);


cout <<b <<endl;

cout<< a <<endl;


}

a)

160

200

b)

160

320

c)

320

160

d)

160

80

8.

Given the function


void fun(int& a, int& b){

int c = a;

a = b;

b = c;


};


What will this code output?


int main(){


int b = 160;

int a = b - 60;


fun(a, b);


cout <<b <<endl;

cout<< a <<endl;


}

a)

100

100

b)

100

160

c)

160

100

d)

160

160

9.

How will the array be displayed after we call fun(arr[1], arr[3]?


void fun(int& a, int& b){

int c = a;

a = b;

b = c;


};


int main(){


int arr[] = { 10, 20, 30 40 }


fun(arr[1], arr[3]);


for(int i = 0; i < sizeof(arr); i ++){

cout<<arr[i] << " ";

}


}

a)

10 40 30 20

b)

20 30 40 10 20 30 40

c)

40 20 30 10

d)

30 40 10 20

10.

Fill this blank to have the function work as instructed:


int practice(int& x){

//multiply x by 2

___________

return 0;

}

a)

x*=2

b)

x**

c)

x*2

d)

return 2*x

11.

Given the function:


int practice(int& x){

...

}


What would be a proper function call for it?


int main() {

int bananas = 10;

int& apple = bananas;


//call the function here

_______


return 0;

}

a)

practice(&2);

b)

practice(bananas);

c)

apples(bananas);

d)

return apples

12.

If the address of a is at 0x2ab3.

What would the following code output?


int a = 20;

int &b = a;


cout<<&a <<endl;

cout<<b;

a)

0x2ab3

0x2ab3

b)

0x2ab3

20

c)

20

20

d)

20

40