Sail E0 Webinar

MCQs

Total Questions : 34 | Page 2 of 4 pages
Question 11. What is the output of this C code?
void foo(int*);
int main()
{
int i = 10, *p = &i;
foo(p++);
}
void foo(int *p)
{
printf("%d\n", *p);
}
  1.    10
  2.    Some garbage value
  3.    Compile time error
  4.    Segmentation fault
 Discuss Question
Answer: Option A. -> 10


None.


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


None.


Question 13. What is the output of this C code?
int main()
{
int i = 11;
int *p = &i;
foo(&p);
printf("%d ", *p);
}
void foo(int *const *p)
{
int j = 10;
*p = &j;
printf("%d ", **p);
}
  1.    Compile time error
  2.    10   10
  3.    Undefined behaviour
  4.    10   11
 Discuss Question
Answer: Option A. -> Compile time error


None.


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


None.


Question 15. What is the output of this C code?
int main()
{
int i = 97, *p = &i;
foo(&i);
printf("%d ", *p);
}
void foo(int *p)
{
int j = 2;
p = &j;
printf("%d ", *p);
}
  1.    2   97
  2.    2   2
  3.    Compile time error
  4.    Segmentation fault/code crash
 Discuss Question
Answer: Option A. -> 2   97


None.


Question 16. What is the output of this C code?
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int **r = &p;
printf("%p %p", *r, a);
}
  1.    Different address is printed
  2.    1   2
  3.    Same address is printed.
  4.    1   1
 Discuss Question
Answer: Option C. -> Same address is printed.


None.


Question 17. What substitution should be made to //-Ref such that ptr1 points to variable C?
int main()
{
int a = 1, b = 2, c = 3;
int *ptr1 = &a;
int **sptr = &ptr1;
//-Ref
}
  1.    *sptr = &c;
  2.    **sptr = &c;
  3.    *ptr1 = &c;
  4.    None of the mentioned.
 Discuss Question
Answer: Option A. -> *sptr = &c;


None.


Question 18. Comment on the output of this C code?
int main()
{
int a = 10;
int **c -= &&a;
}
  1.    You cannot apply any arithmetic operand to a pointer.
  2.    We don't have address of an address operator
  3.    Both (a) and (b)
  4.    None of the mentioned.
 Discuss Question
Answer: Option B. -> We don't have address of an address operator


None.


Question 19. Which of the following declaration throw run-time error?
  1.    int **c = &c;
  2.    int **c = &*c;
  3.    int **c = **c;
  4.    None of the mentioned.
 Discuss Question
Answer: Option D. -> None of the mentioned.


None.


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


None.


Latest Videos

Latest Test Papers