Single Choice Not Set

Q

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


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

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

Choose the Best Option

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

  • A 10 4294967286 0 0
  • B 10 65526 0 0
  • C A and B
  • D None
Correct Answer

Explanation

Output of Turbo C++ 3.0: 10 65526 0 0

10 65526 0 0

Turbo C ++4.5: 10 65526 0 0

10 65526 0 0

Linux GCC: 10 4294967286 0 0

10 4294967286 0 0

Visual C++: 10 4294967286 0 0

10 4294967286 0 0

a=(signed)10u;

signed value of 10u is +10

so, a=10

b=(unsigned)-10;

unsigned value of -10 is :

MAX_VALUE_OF_UNSIGNED_INT – 10 + 1

In turbo c 3.0 complier max value of unsigned int is 65535

So, b = 65526

y = (signed)10u + (unsigned)-10;

= 10 + 65526 = 65536 = 0 (Since 65536 is beyond the range of unsigned int. zero is its corresponding cyclic vlaue)

X = y = 0

Share This Question

Challenge a friend or share with your study group.