1. Look at the following code. int numbers[] = {0, 1, 2, 3, 4 }; int *ptr = numb
ID: 3547299 • Letter: 1
Question
1.
Look at the following code.
int numbers[] = {0, 1, 2, 3, 4 };
int *ptr = numbers;
ptr++;
After this code executes, which of the following statements is true?
A) ptr will hold the address of the 2nd byte within the element numbers[0]
B) This code will not compile.
C) ptr will hold the address of numbers[1]
D) ptr will hold the address of numbers[0]
2.
What will the following code output?
int *numbers = new int[5];
for (int i = 0; i <= 4; i++)
*(numbers + i) = i;
cout << numbers[2] << endl;
A) Five memory addresses
B) 0
C) 3
D) 2
E) 1
3.
What will the following code output?
int number = 22;
int *var = &number;
cout << var << endl;
A) 22
B) The address of the number variable
C) An asterisk followed by 22
D) An asterisk followed by the address of the number variable
4.
What will the following code output?
int number = 22;
int *var = &number;
cout << *var << endl;
A) 22
B) An asterisk followed by the address of the number variable
C) An asterisk followed by 22
D) The address of the number variable
5.
int numbers [] = {9,5,6,8,1};
int* ptr = numbers;
sum += *ptr++;
After the above statement executes...
A) sum = 9 and ptr is pointing at numbers[1]
B) the program ends with an error
C) sum = 10 and ptr is pointing at numbers[0]
D) sum = 0 and ptr is pointing at numbers[0]
Explanation / Answer
1. C) ptr will hold the address of numbers[1]
2. D) 2
3. B) The address of the number variable
4. A) 22
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.