SOLUTIONS RATED A+
✔✔Assume a varible is declared in a block of code within a pair of curly braces. The
scope of the variable - ✔✔starts from its declaration point and extends to the end of the
block.
✔✔Given a C declaration: char a[] = "Hello World"; What can be used as the initial
address of array a[]? Select all correct answers. - ✔✔*a[0]
&a[0] (check with professor)
✔✔Given a declaration: char a[] = "Hello World"; What is the size (in bytes) of the array
a[]? - ✔✔12 bytes
✔✔Which of the following C assignment statements (assign a value to a variable at the
semantic level) will NOT cause a compilation error?
Assume the array has been declared as: char a[5]; - ✔✔a[0] = 'h';
✔✔Which of the following statements will assign the address of the variable int myInt to
the pointer int* myPtr? - ✔✔int* myPtr = &myInt;
✔✔Given the following:
int num1 = 5; //addressed at 1877112
int num2 = 15; //addressed at 1877300
int num3 = 20; //addressed at 1877192
double d1 = 1.05; //addressed at 1374376
double d2 = 2.25; //addressed at 1374360
double d3 = 3.14; //addressed at 1374344
After these statements:
int* ptr1 = &num3
ptr1 = ptr1 + 5;
What will be the address contained in ptr1? - ✔✔1877212
✔✔Which of the following statements will allow me to give the value of 10 to the
memory int* myPtr points to? - ✔✔*myPtr = 10;
✔✔int num1 = 5; //addressed at 1767612
int num2 = 10; //addressed at 1767600
,int num3 = 15; //addressed at 1767588
char ch1 = 'a'; //addressed at 3734375
char ch2 = 'b'; //addressed at 3734363
char ch3 = 'c'; //addressed at 3734351
char* chPtr = &ch3;
int* iPtr = &num3;
*iPtr = num3 *(times) 8;
'*chPtr' = '*iPtr;'
What will the following statement output?
cout << ch3; - ✔✔'x'
✔✔(True or False) Multiple pointers can reference the same objects. - ✔✔True
✔✔C/C++ has 2 pointer operators, which operator represents the name of the address?
(Commonly refer as l-value.) - ✔✔Asterisk (*)
✔✔Given this snippet of code, what is the value of x after executing the last statement?
int x = 10, *y;
y = &x;
y = y + 1;
*y = 100; - ✔✔10
✔✔Given this snippet of code, what is the value of x after executing the last statement?
int x = 10, *y;
y = &x;
*y = 100; - ✔✔100
✔✔Given this snippet of code, what is the value of z after executing the last statement?
, int x = 10, *y, **z;
z = &y;
y = &x;
*y = 100; - ✔✔None of the above (Memory Address)
✔✔A pointer variable can take the address of a memory location as its value. Read the
given program.
#include <stdio.h>
main() {
int a = 20, b = 30, *p, *q, **r;
p = &a;
*p = 50;
q = &b;
*q = 70;
r = &p;
**r = 90;
printf("%d\n", a); // 1st printf statement
printf("%d\n", b); // 2nd printf statement
a = 20;
b = 80;
printf("%d\n", **r); // 3rd printf statement
}
Answer the following three questions.
1.The output of the 1st printf statement is [first].
2. The output of the 2nd printf statement is [second].
3.The output of the 3rd printf statement is [third]. - ✔✔1.The output of the 1st printf
statement is Correct 90.
2. The output of the 2nd printf statement is Correct 70.
3.The output of the 3rd printf statement is Correct 20.
✔✔We use "Pass by Constant Reference" when: - ✔✔Function does not want to modify
the value, the value is expensive to copy and NULL is not valid