Why this statement is legal C statement?? int apple = ‘c’ ; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why this statement is legal C statement?? int apple = ‘c’ ;

Why this statement is legal C statement?? int apple = ‘c’ ; Isn't int for numbers??

22nd Mar 2021, 7:27 AM
STOP
STOP - avatar
2 Answers
+ 1
its legal because C reads every character as an integer. for instance, test this: int apple = 'a'; printf("int: %d\nchar: %d",apple,apple); // will print 97 a because to C, the character 'a' and the number 97 are the same thing.
22nd Mar 2021, 7:58 AM
Slick
Slick - avatar
+ 1
Integer for any known character is its ASCII value in most programming language. Refer this: http://www.asciitable.com/
22nd Mar 2021, 9:16 AM
Arun Bhattacharya
Arun Bhattacharya - avatar