ExamVeda
Login
Home
41
What will be the output?
void main(){ 
    int a=10, b=20;
    char x=1, y=0;
    if(a,b,x,y){ 
        printf("EXAM"); 
    } 
}
Discuss
Answer & Solution
Answer: Option D
Solution:

The correct answer is D. Nothing is printed.

In the given code, the if statement condition consists of multiple expressions separated by commas (,). The comma operator evaluates each expression from left to right and returns the result of the last expression.

In this case, the expressions a, b, x, and y are used as the condition. Since they are non-zero values (10, 20, 1, and 0 respectively), the condition is considered true. However, the comma operator only returns the result of the last expression (y), which is 0 (false).

Since the condition evaluates to false, the code block within the if statement (printf("EXAM");) is not executed, resulting in nothing being printed.

42
What number will z in the sample code given below?
int z, x=5, y= -10, a=4, b=2;
z = x++ - --y*b/a;
Discuss
Answer & Solution
Answer: Option D
Solution:

C Operator Precedence Table
According to precedence table execution of the given operators are as follows:
1. x++(Postfix operator) i.e x will become 5
2. y--(Prefix operator) i.e y will become -11
3. * and / have same priority so they will be executed according to their associativity i.e left to right. So, *(Multiplication) will execute first and then /(division).
4. -(Subtraction)

So the complete expression would be
5 - (-11)*2/4 = 5 - (-22)/4 = 5 - (-5) = 5 + 5 = 10.

43
What is the output of the following statements?
int i = 0;
printf("%d %d", i, i++);
Discuss
Answer & Solution
Answer: Option B
Solution:
Since the evaluation is from right to left.
So when the print statement execute value of i = 0
Since its execute from right to left when i++ will be execute first and print value 0 (since its post increment ) and after printing 0 value of i become 1.
So it its prints for 1 for next i.
44
What is the output of the following statements?
int b=15, c=5, d=8, e=8, a;
a = b>c ? c>d ? 12 : d>e ? 13 : 14 : 15;
printf("%d", a);
Discuss
Answer & Solution
Answer: Option B
Solution:
Expression
a = b>c ? c>d ? 12 : d>e ? 13 : 14 : 15;
can be rewritten as
if(b>c)
{
   if(c>d)
      a = 12;
   else
   {
      if(d>e)
         a = 13;
      else
         a = 14;
   }
}
else
{
   a = 15;
}
45
What will be the output of the following code fragment?
void main()
{
   printf("%x",-1<<4);
}
Discuss
Answer & Solution
Answer: Option A
Solution:

-1 will be represented in binary form as:
1111 1111 1111 1111

Now -1<<4 means 1 is Shifted towards left by 4 positions, hence it becomes:
1111 1111 1111 0000 in hexadecimal form - fff0.

46
Find the output of the following program.
#include<stdio.h>
void main()
{
   int y=10;
   if(y++>9 && y++!=10 && y++>11)
      printf("%d", y);
   else
      printf("%d", y);
}
Discuss
Answer & Solution
Answer: Option C
Solution:
All the three condition in if is true.
if(y++>9 && y++!=10 && y++>11) such as
1st condition : 10++ > 9 is true and value of y is increase by 1 i.e y =11
2nd condition : 11++ != 10 is also ture and value of y is increase by 1 i.e y =12
3rd condition : 12++ > 11 is also ture and value of y is increase by 1 i.e y =13
Therefore if is excuted and print the value of y = 13
47
Find the output of the following program.
#include<stdio.h>
void main()
{
   int y=10;
   if(y++>9 && y++!=11 && y++>11)
      printf("%d", y);
   else
      printf("%d", y);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

Since the second condition is false so, further conditions will not be checked, it will be skipped.

48
Determine output of the following program code.
#include<stdio.h>
void main()
{
   int a, b=7;
   a = b<4 ? b<<1 : ++b>4 ? 7>>1 : a;
   printf("%d %d", a, b);
}
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
49
Choose the correct output for the following program.
#include<stdio.h>
void main()
{
   int a=10, b=11, c=13, d;
   d = (a=c, b+=a, c=a+b+c);
   printf("%d %d %d %d", d, a, b, c);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

For any comma separated expression the outcome is the right most part.

50
Consider the following program fragment, and choose the correct one.
void main()
{
   int a, b = 2, c;
   a = 2 * (b++);
   c = 2 * (++b);
}
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board