MCQ Single Best Answer Not Set

Q

What will be output when you will execute following c code?


 #include<stdio.h>
  int main(){
    signed x;
    unsigned y;
    x = 10 +- 10u + 10u +- 10;
    y = x;
    if(x==y)
         printf("%d %d",x,y);
    else if(x!=y)
         printf("%u  %u",x,y);
    return 0;
}

ID: #902 Data Types in C Language 3,184 views
Question Info
#902Q ID
Not SetDifficulty
Data Types in C LanguageTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 65536 -10
  • B 0 65536
  • C 0 0
  • D Compilation error
Correct Answer: Option C

Explanation

Consider on the expression:

x = 10 +- 10u + 10u +- 10;

10: It is signed integer constant.

10u: It is unsigned integer constant.

X: It is signed integer variable.

In any binary operation of dissimilar data type for example: a + b

Lower data type operand always automatically type cast into the operand of higher data type before performing the operation and result will be higher data type.

As we know operators enjoy higher precedence than binary operators. So our expression is:

x = 10 + (-10u) + 10u + (-10);

= 10 + -10 + 10 + (-10);

= 0

Note: Signed is higher data type than unsigned int.

So, Corresponding signed value of unsigned 10u is +10

Share This Question

Challenge a friend or share with your study group.