OOP344 Quiz2 20093

From CDOT Wiki
Jump to: navigation, search
OOP344  20093                  Quiz 2

1 – What is the value of  X?
int X = printf("A: %d B: %.2lf\n", 123, 123.456);

A: 2     B: -1     C: 1     D: 16     E: 17

2 – What is the value of X?
  int a;

  char b;

  int X = scanf("%c%c%d%d%c", &b, &b, &a, &a, &b);
  if user enters: A123BC
A: -1           B: 3         C: 4        D: 5      E: 6

3 – If 
void* ptr = (void*)1234500;
ptr++;

Then value of ptr will be:
A: 1234501     B: 1234502    C: 1234504    D: 1234508    E: The code will not compile

4 – If 
short int* ptr = (short int*)1234500;
ptr++;

Then value of ptr will be:
A: 1234501     B: 1234502     C: 1234504    D: 1234508    E: The code will not compile

5 – Having the following statement:
The number “123” as an address for a short integer.
We can surly say:
A:  It is valid because 123 is an integer and like any other integer number, it could be and address for a short integer.  
B: It is invalid because it too small to be an address
C: It is invalid because it is an odd number
D: It is invalid because it is not coefficient of 2, that is the size of a short integer.
E: It is invalid because of all said in C and D.

6 – Having 
char ch = 127;
ch++;
The value of ch will be:
A: 128       B: -128     C: 0      D: -127        E: -1 

Having:
int X[2][3][2] = {  {{1,2},{3,4},{5,6} },    {{7,8},{9,10},{11,12} }    };
int* p;
And knowing that X is located at address 12300 in memory:

7 – the pointer notation for X[0][2][1] is:
A:  *(*(*(X+0)+2)+1)      
B:  *(*(*(X)+2)+1)     
C:  *(*(*X+2)+1)    
D:  *(*(*(X+1)+2)+0)   
E: All A, B and C

8 - (X+1) is:
A: 12324          
B: 12312         
C: 12306           
D: 12305        
E: 12304

9 – (&X[0][0] + 1) is:
A: 12301          
B: 12302         
C: 12304            
D: 12308        
E: None of the above choices

10 – if  p = (int*) X;  and  p++;
then “p” will be:
A: 12324          
B: 12312         
C: 12306           
D: 12305        
E: 12304