Sail E0 Webinar

MCQs

Total Questions : 37 | Page 4 of 4 pages
Question 31.

What will be output if you compile following c code ?


void main()
{
char *ptr="Placementadda";
printf("%d",-3[ptr]);
}


  1.    -300
  2.    -103
  3.    Compile Error
  4.    Garbage Value
 Discuss Question
Answer: Option B. -> -103


-3[ptr]



= -*(3+ptr)



= -*(ptr+3)



= -ptr[3]


= -103  //ASCII value of character ‘e’ is 103


Question 32.

What will be output if you compile following c code ?


void main()
{
char *str = "Placementadda";
printf("%d",printf("%s",str));
}


  1.    Placementadda
  2.    Placementadda
  3.    Null
  4.    It will print nothing
  5.    compile error
 Discuss Question
Answer: Option E. -> compile error


We cannot copy anything using strcpy function to the character pointer pointing to NULL.


Question 33.

What will be output if you compile following c code ?


void main()
{
char str[] = "Placementadda";
str = str + 5;
printf("%s ",str));
}


  1.    Placementadda
  2.    mentadda
  3.    Error
  4.    None of the above
 Discuss Question
Answer: Option C. -> Error

Error: since name of array is a constant pointer and can't be altered



Question 34.

What will be output if you compile following c code ?


void main()
{
char data[2][3][2]={0,1,2,3,4,5,6,7,8,9,10,11};
printf("%o",data[0][2][1]);
}


  1.    5
  2.    6
  3.    Compile Error
  4.    None of the above
 Discuss Question
Answer: Option A. -> 5

%o in printf statement is used to print number in the octal format.


Question 35.

What will be output if you compile following c code ?


void main()
{
char str[13] = "Placementadda";
printf("%s",str));
}


  1.    Placementadd
  2.    P
  3.    Garbage Value
  4.    Compile Error
 Discuss Question
Answer: Option C. -> Garbage Value


Size of a character array should
one greater than total number of characters in any string which it stores. In c
every string has one terminating null character. This represents end of the
string.
So in the string "Placementadda” , there
are 13 characters and they are ‘P’,’l’,’a’,’c’,’e’,’m’,’e’, ‘n’,’t’,’a’,’d’,’d’,’a’ and ‘’. Size of
array arr is 13. So array arr will store only first 13 characters and it
will note store null character.

Question 36.

What will be output if you compile following c code ?


void main()
{
char str[] = "Placementadda";
func(str+5);
}
func(char *str)
{
printf("%s",str);
}


  1.    Placementadda
  2.    mentadda
  3.    Error
  4.    None of the above
 Discuss Question
Answer: Option B. -> mentadda



Question 37.

What will be output if you compile following c code ?


void main()
{
printf(5+'Placementadda');
}


  1.    Error
  2.    Placementadda
  3.    mentadda
  4.    None of the above
 Discuss Question
Answer: Option C. -> mentadda


Latest Videos

Latest Test Papers