[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

C Programming :: Declarations and Initializations - Discussion

Home > C Programming > Declarations and Initializations > MCQs Questions Discussion

65 / 54

What will be the result of the following program?

#include <stdio.h>
void main()
      {
       unsigned short a=-1;
       unsigned char b=a;
       printf("%d %d ",a,b);
      }
What is output of the program?

A65535 -1

B65535 65535

C65535 255

D-1 -1

ENone of above

Answer: Option (Login/Signup)

Show Explanation

Clearly, a cannot be assigned with -1, as -1 is not in the range of unsigned short. So, when we try to assign -1 to a, automatically 65535 gets assigned to a, as it follows a cyclic pattern.

Same is the result when we try to assign -1 to b, which is an unsigned char. The value range for unsigned char is from 0 to 255. So, automatically, 255 gets assigned to b.

Hence, the output is 65535 255.

Asked In :: Cisco

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here