ExamVeda
Login
Home
1
Determine output:
void main()
{
      int const *p=5;
      printf("%d", ++(*p));
}
Discuss
Answer & Solution
Answer: Option D
Solution:

p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".

2
Determine Output:
void main()
{
      char s[]="man";
      int i;
      for(i=0; s[i]; i++)
            printf("%c%c%c%c ", s[i], *(s+i), *(i+s), i[s]);
}
Discuss
Answer & Solution
Answer: Option D
Solution:
Correct Output : mmmm aaaa nnnn
s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the case of C it is same as s[i].
3
Determine Output:
void main()
{
      float me = 1.1;
      double you = 1.1;
      if(me==you)
            printf("I hate Examveda");
      else
            printf("I love Examveda");
}
Discuss
Answer & Solution
Answer: Option B
Solution:

For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.
Rule of Thumb: Never compare or at-least be cautious when using floating point numbers with relational operators (== , >, <, <=, >=,!= ) .

4
Determine Output:
void main()
{
      static int var = 5;
      printf("%d ", var--);
      if(var)
            main();
}
Discuss
Answer & Solution
Answer: Option B
Solution:

When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively.

5
Determine Output:
void main()
{
      char *p;
      printf("%d %d", sizeof(*p), sizeof(p));
}
Discuss
Answer & Solution
Answer: Option B
Solution:

The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2.

6
Determine the Final Output:
void main()
{
      printf("\nab");
      printf("\bsi");
      printf("\rha");
}
Discuss
Answer & Solution
Answer: Option D
Solution:

\n - newline - printf("\nab"); - Prints ab
\b - backspace - printf("\bsi"); - firstly '\b' removes 'b' from 'ab ' and then prints 'si'. So after execution of printf

7
Determine Output:
void main()
{
      int i=10;
      i=!i>14;
      printf("i=%d", i);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

In the expression !i>14 , NOT (!) operator has more precedence than ">" symbol. ! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14 is false (zero).

8
Determine Output:
void main()
{
      int c = - -2;
      printf("c=%d", c);
}
Discuss
Answer & Solution
Answer: Option C
Solution:
In the given C program code snippet:

void main()
{
      int c = - -2;
      printf("c=%d", c);
}


The line int c = - -2; is evaluated as follows:

1. The expression `- -2` involves two consecutive negative signs. 2. The first negative sign (`-`) acts as the unary minus operator, and the second negative sign (`-`) is also a unary operator. 3. When two negative signs are used together, they effectively cancel each other out, so `- -2` becomes `2`.

Therefore, the variable `c` is assigned the value `2`.

The output of the `printf` function will be: 2
9
Determine Output:
#define int char
void main()
{
      int i = 65;
      printf("sizeof(i)=%d", sizeof(i));
}
Discuss
Answer & Solution
Answer: Option B
Solution:

Since the #define replaces the string int by the macro char.

10
Determine Output:
void main()
{
      int i=3;
      switch(i)
      {
            default: printf("zero");
            case 1: printf("one"); break;
            case 2: printf("two"); break;
            case 3: printf("three"); break;
      }
}
Discuss
Answer & Solution
Answer: Option B
Solution:

The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.