ExamVeda
Login
Home
11
Determine Output:
void main()
{
      char string[]="Hello World";
      display(string);
}
void display(char *string)
{
      printf("%s", string);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

Type mismatch in redeclaration of function display.
In third line, when the function display is encountered, the compiler doesn't know anything about the function display. It assumes the arguments and return types to be integers, (which is the default type). When it sees the actual function display, the arguments and type contradicts with what it has assumed previously. Hence a compile time error occurs.

12
Determine Output:
void main()
{
      int i=5;
      printf("%d%d%d%d%d", i++, i--, ++i, --i, i);
}
Discuss
Answer & Solution
Answer: Option A
Solution:
The arguments in a function call are pushed into the stack from left to right. The evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result. See the picture below
C Miscellaneous mcq solution image
13
Determine Output:
#define square(x) x*x
void main()
{
      int i;
      i = 64/square(4);
      printf("%d", i);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

The macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4 . Since / and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64

14
Determine Output:
void main()
{
      char *p="hi friends", *p1;
      p1=p;
      while(*p!='\0') ++*p++;
      printf("%s", p1);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

++*p++ will be parse in the given order :
1. *p that is value at the location currently pointed by p will be taken
2. ++*p the retrieved value will be incremented
3. when ; is encountered the location will be incremented that is p++ will be executed.

15
Determine Output:
#include<stdio.h>
#define a 10
void main()
{
      #define a 50
      printf("%d", a);
}
Discuss
Answer & Solution
Answer: Option A
Solution:

The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken.

16
Determine Output:
#define clrscr() 100
void main()
{
      clrscr();
      printf("%d", clrscr());
}
Discuss
Answer & Solution
Answer: Option C
Solution:

Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 100 occurs. The input program to compiler looks like this :

void main()
{
      100;
      printf("%d", 100);
}

Note: 100; is an executable statement but with no action. So it doesn't give any problem.

17
Determine Output:
void main()
{
      printf("%p", main);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

Function names are just addresses (just like array names are addresses). main() is also a function. So the address of function main will be printed. %p in printf() specifies that the argument is an address. They are printed as hexadecimal numbers.

18
Determine Output:
void main()
{
      char far *farther, *farthest;
      printf("%d..%d", sizeof(farther), sizeof(farthest));
}
Discuss
Answer & Solution
Answer: Option A
Solution:

The second pointer is of char type and is not a far pointer.

19
Determine Output:
void main()
{
      char *p;
      p="Hello";
      printf("%c", *&*p);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

* is a dereference operator & is a reference operator. They can be applied any number of times provided it is meaningful. Here p points to the first character in the string "Hello". *p dereferences it and so its value is H. Again & references it to an address and * dereferences it to the value H.

20
Determine Output:
void main()
{
      int i=1;
      while(i<=5)
      {
            printf("%d", i);
            if(i>2)
                  goto here;
            i++;
      }
}
fun()
{
      here:  printf("PP");
}
Discuss
Answer & Solution
Answer: Option C
Solution:

Compiler error: Undefined label 'here' in function main
Labels have functions scope, in other words The scope of the labels is limited to functions. The label 'here' is available in function fun() Hence it is not visible in function main.