ExamVeda
Login
Home
31
Determine Output:
void main()
{
      char not; 
      not = !2;
      printf("%d", not);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

! is a logical operator. In C the value 0 is considered to be the boolean value FALSE, and any non-zero value is considered to be the boolean value TRUE. Here 2 is a non-zero value so TRUE. !TRUE is FALSE (0) so it prints 0.

32
Determine Output:
#include<stdio.h>
void main()
{
      register i=5;
      char j[]= "hello";
      printf("%s %d", j, i);
}
Discuss
Answer & Solution
Answer: Option A
Solution:

If you declare i as register compiler will treat it as ordinary integer and it will take integer value. i value may be stored either in register or in memory.

33
Determine Output:
void main()
{
      int i=5, j=6, z;
      printf("%d", i+++j);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

The expression i+++j is treated as ((i++) + j)

34
Determine Output:
void main()
{
      int i = abc(10);
      printf("%d", --i);
}
int abc(int i)
{
      return(i++);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

"return(i++)", it will first return i and then increment it. i.e. 10 will be returned.

35
Determine Output:
void main()
{
      char a[]="12345"; 
      int i = strlen(a); 
      printf("%d", ++i);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

The char array 'a' will hold the initialized string, whose length will be counted from 0 till the null character. Hence the 'i' will hold the value equal to 5, after the pre-increment in the printf statement, then 6 will be printed.

36
Determine Output:
void main()
{
      int i;
      char a[]="�"; 
      if(printf("%sn", a))
            printf("Ok here n");
      else
            printf("Forget itn");
}
Discuss
Answer & Solution
Answer: Option A
Solution:

Printf will return how many characters does it print. Hence printing a null character returns 1 which makes the if statement true, thus "Ok here" is printed.

37
Determine Output:
void main()
{
      int i=i++, j=j++, k=k++;
      printf("%d %d %d", i, j, k);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

An identifier is available to use in program code from the point of its declaration. So expressions such as i = i++ are valid statements. The i, j and k are automatic variables and so they contain some garbage value.

38
Determine Output:
void main()
{
      static int i=i++, j=j++,  k=k++;
      printf("%d %d %d", i, j, k);
}
Discuss
Answer & Solution
Answer: Option A
Solution:

Since static variables are initialized to zero by default.

39
Determine Output:
#define prod(a,b)  a*b
void main()
{
      int x=3, y=4;
      printf("%d", prod(x+2, y-1));
}
Discuss
Answer & Solution
Answer: Option B
Solution:

The macro expands and evaluates to as:
x+2*y-1 => x+(2*y)-1 => 10

40
Determine Output:
void main()
{
      char p[]="%dn";
      p[1] = 'c';
      printf(p, 65);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

Due to the assignment p[1] = 'c' the string becomes, "%c\n". Since this string becomes the format string for printf and ASCII value of 65 is 'A', the same gets printed.