Sail E0 Webinar

MCQs

Total Questions : 64 | Page 6 of 7 pages
Question 51.

What will be output of following program?




#include<stdio.h>
#include<string.h>
int main()
{
int register a;
scanf("%d",&a); // say a = 10
printf("%d",a);
return 0;
}


  1.    10
  2.    Address
  3.    0
  4.    Compilation error
  5.    None of the above
 Discuss Question
Answer: Option D. -> Compilation error

Register data type stores in CPU. So it has not any memory address. Hence we cannot write &a.



Question 52.
What will be the output of the following program :
#include<stdio.h>
main()
{
int val=1234;
int* ptr=&val;
printf("%d %d",val,*ptr++);
}
  1.    1234 1234
  2.    1235 1235
  3.    1234 1235
  4.    1235 1234
 Discuss Question
Answer: Option A. -> 1234 1234


Question 53.
What will be the output of the following program :
#include<stdio.h>
main()
{
int val=1234;
int* ptr=&val;
printf("%d %d",++val,(*(int *)ptr)--);
}
  1.    1234 1233
  2.    1235 1234
  3.    1234 1234
  4.    None of these
 Discuss Question
Answer: Option C. -> 1234 1234



Question 54.

What will be output of following program?



#include<stdio.h>
#include<string.h>
int main()
{
int a,b,c,d;
char *p = (char*)0;
int *q = (int*q)0;
float *r = (float*)0;
double *s = 0;
a = ( int)(p+1);
b = ( int)(q+1);
c = ( int)(r+1);
d = ( int)(s+1);
printf("%d %d %d %d",a,b,c,d);
return 0;
}


  1.    2 2 2 2
  2.    1 2 4 8
  3.    1 2 2 4
  4.    Compilation error
  5.    None of the above
 Discuss Question
Answer: Option B. -> 1 2 4 8

Address + 1 = next address



Question 55.


In which header file is the NULL macro defined?



  1.    stdio.h
  2.    stddef.h
  3.    stdio.h and stddef.h
  4.    math.h
 Discuss Question
Answer: Option C. -> stdio.h and stddef.h

The macro "NULL" is defined in locale.h, stddef.h, stdio.h, stdlib.h, string.h, time.h, and wchar.h.



Question 56.
What will be the output of the following program :
#include<stdio.h>
main()
{
int val=1234;
int* ptr=&val;
printf("%d %d",++val,*ptr);
}
  1.    1234 1234
  2.    1235 1235
  3.    1234 1235
  4.    1235 1234
 Discuss Question
Answer: Option D. -> 1235 1234


Question 57.
What will be the output of the following program :
#include<stdio.h>
main()
{
int a=555,*ptr=&a,b=*ptr=777;
printf("%d %d",--*&b,*(int *)&b);
}
  1.    Compile Error
  2.    776 777
  3.    554 555
  4.    None of these
 Discuss Question
Answer: Option B. -> 776 777


Question 58.

What will be output of following program?


#include<stdio.h>
int main()
{
int i = 5;
int *p;
p = &i;
printf("%u %u",*&p, &*p);
return 0;
}
  1.    5 Address
  2.    Address Address
  3.    Address 5
  4.    Compilation error
  5.    None of the above
 Discuss Question
Answer: Option B. -> Address Address

Since * and & always cancel to each other.


i.e. *&a = a



so *&p = p which store address of integer i


&*p = &*(&i) //since p = &i


= &(*&i)

= &i

So second output is also address of i



Question 59.
What will be the output of the following program :
#include<stdio.h>
main()
{
int a=555,*ptr=&a,b=*ptr;
printf("%d %d %d",++a,--b,*ptr++);
}
  1.    Compile error
  2.    555 554 555
  3.    556 554 555
  4.    557 554 555
 Discuss Question
Answer: Option C. -> 556 554 555


Question 60.
What will be the output of the following program :
#include<stdio.h>
main()
{
int val=1234;
int* ptr=&val;
printf("%d %d",val,++*ptr);
}
  1.    1234 1234
  2.    1235 1235
  3.    1234 1235
  4.    1235 1234
 Discuss Question
Answer: Option B. -> 1235 1235


Latest Videos

Latest Test Papers