NEW
Font size
WorksheetsC++ References
Total questions: 12
Worksheet time: 36mins
In C++ a variable that has an & appended is storing a(n):
value
address
integer
string
The "&" symbol is called a(n):
sandpaper
ampersand
percentage sign
andthisthat
I have a variable int a = 2;
then a variable int& b = a;
What happens if I change the value of b
Nothing
a changes as well
b gets bigger
a disappears
Which of these looks like a possible output
int variable = 5;
cout<<&variable;
5
0x7ffc8d64e404
&5
this would throw an error
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;
160
160
0x7ff
160
160
0x7ff
0x7ff
0x7ff
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;
}
160 160
170
b
22xff
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;
}
160
200
160
320
320
160
160
80
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;
}
100
100
100
160
160
100
160
160
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] << " ";
}
}
10 40 30 20
20 30 40 10 20 30 40
40 20 30 10
30 40 10 20
Fill this blank to have the function work as instructed:
int practice(int& x){
//multiply x by 2
___________
return 0;
}
x*=2
x**
x*2
return 2*x
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;
}
practice(&2);
practice(bananas);
apples(bananas);
return apples
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;
0x2ab3
0x2ab3
0x2ab3
20
20
20
20
40
