Click here to Skip to main content
15,905,148 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Find output of below program

int a;
a= 'b' - 'a';
printf("%d\n",a);

a) compilation error
b) 97
c) 98
d) 0

What I have tried:

At first i thought the output would be 1 as the subtraction of ASCII values.but on execution it is giving errors. Since i am a beginner in C. Hope you will help me out !!
Posted
Updated 24-Nov-18 5:14am
Comments
Patrice T 24-Nov-18 3:21am    
Which error message ?

The solution I get is what I'd expect: 1
That's using two different compilers:
Virtual-C IDE[^]
And
Online C Compiler - online editor[^]
Both give the same results.

I can't think of a compiler that would (or should) give an error or any other result!
I'd check the question really carefully and make sure you haven't missed something or mistyped it here.
 
Share this answer
 
The code you poste is perfect valid C one. The following program
C
#include <stdio.h>

int main()
{
  int a;
  a= 'b' - 'a';
  printf("%d\n",a);
  return 0;
}

compiles ('warninglessly') and runs fine, producing the output
1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900