Last Updated : 14 Feb, 2019

What will be the output of the following program?

#include<stdio.h> 
int main() 
{ 
    int x = 10; 
    char y = \'a\';    
    float z;

    x = x + y;
    z = x + 1; 
    y = y + 1;

    printf(\"%d %c %f\", x, y, z); 

    return 0;
} 

(A) 107 b 108.00
(B) 107 b 108.000000
(C) Error
(D) None of these


Answer: (B)

Explanation: As x is int and y is char, therefore x = x + y = 10 + 97(ASCII value of \’a\’) = 107
As z is float and x is int, therefore z = x + 1 = 107.000000(float value of x) + 1 = 108.000000
As y is char, therefore y = y + 1 = 97(ASCII value of \’a\’) + 1 = 98 = \’b\'(Char value of ASCII 98)


Quiz of this Question


Share your thoughts in the comments