[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

47 / 54

What is the output of the following 'C' program ?

#include<stdio.h>
int main()
{
 char c = 255; 
 printf ("%d",c);
 return 0;
}

Aillegal character assignment

Bprints -1

Cprints 2

Dprints 255

Answer: Option (Login/Signup)

Show Explanation

Before that, we should know that char can store numbers only -128 to 127. The most significant bit is kept for the sign bit. Clearly, 11111111 represents a negative number. To check which number it represents we find the 2’s complement of it, which is 00000001, which is nothing but 1 in decimal.

Hence, 11111111 represents -1, which is the required output.

 

Asked In :: Global Edge

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here