Sail E0 Webinar

MCQs

Total Questions : 34 | Page 1 of 4 pages
Question 1. What is the output of this C code?
int main()
{
char *p = NULL;
char *q = 0;
if (p)
printf(" p ");
else
printf("nullp");
if (q)
printf("q\n");
else
printf(" nullq\n");
}
  1.    nullp  nullq
  2.    Depends on the compiler
  3.    x nullq where x can be p or nullp depending on the value of NULL
  4.    p   q
 Discuss Question
Answer: Option A. -> nullp  nullq


None.


Question 2. What is the output of this C code?
int main()
{
int i = 10;
void *p = &i;
printf("%d\n", (int)*p);
return 0;
}
  1.    Compile time error
  2.    Segmentation fault/runtime crash
  3.    10
  4.    Undefined behaviour
 Discuss Question
Answer: Option A. -> Compile time error


None.


Question 3. What is the output of this C code?
int *f();
int main()
{
int *p = f();
printf("%d\n", *p);
}
int *f()
{
int *j = (int*)malloc(sizeof(int));
*j = 10;
return j;
}
  1.    10
  2.    Compile time error
  3.    Segmentation fault/runtime crash since pointer to local variable is returned
  4.    Undefined behaviour
 Discuss Question
Answer: Option A. -> 10


None.


Question 4. What is the output of this C code?
int main()
{
int i = 10;
void *p = &i;
printf("%f\n", *(float*)p);
return 0;
}
  1.    Compile time error
  2.    Undefined behaviour
  3.    10
  4.    0.000000
 Discuss Question
Answer: Option D. -> 0.000000


None.


Question 5. What is the output of this C code?
int *f();
int main()
{
int *p = f();
printf("%d\n", *p);
}
int *f()
{
int j = 10;
return &j;
}
  1.    10
  2.    Compile time error
  3.    Segmentation fault/runtime crash
  4.    Undefined behaviour
 Discuss Question
Answer: Option A. -> 10


None.


Question 6. What is the output of this C code?
int
main()
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
printf("%d,%d/n", *ptr, a);
}
  1.    10,10
  2.    10,11
  3.    11,10
  4.    11,11
 Discuss Question
Answer: Option D. -> 11,11


None.


Question 7. What is the output of this C code?
int x = 0;
void main()
{
int *ptr = &x;
printf("%p\n", ptr);
x++;
printf("%p\n ", ptr);
}
  1.    Same address
  2.    Different address
  3.    Compile time error
  4.    Varies
 Discuss Question
Answer: Option A. -> Same address


None.


Question 8. Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0)?
  1.    int *ptr = &a;
  2.    int *ptr = &a "“ &a;
  3.    int *ptr = a "“ a;
  4.    All of the mentioned
 Discuss Question
Answer: Option A. -> int *ptr = &a;


None.


Question 9. Which is an indirection operator among the following?
  1.    &
  2.    *
  3.    ->
  4.    .
 Discuss Question
Answer: Option B. -> *


None.


Question 10. Comment on the following?
const int *ptr;
  1.    You cannot change the value pointed by ptr
  2.    You cannot change the pointer ptr itself
  3.    Both (a) and (b)
  4.    You can change the pointer as well as the value pointed by it
 Discuss Question
Answer: Option A. -> You cannot change the value pointed by ptr


None.


Latest Videos

Latest Test Papers