0

i entered letter "g" instead of integer value for a & b for fun, but code "a+b" gave me value "8", why? lang-C.

#include <stdio.h> int main() { int a, b; printf("Enter two numbers:"); scanf("%d %d", &a, &b); printf("\nSum: %d", a+b); return 0; }

9th Jun 2019, 6:56 AM
Jaswant Singh
4 Answers
+ 3
in C each character has its how integer representation, or let me just say character data is just like integer data type, you only convert to Ascii, just as Anhjje 🐑 have represented it for you, because you use the integer specifier all input will be converted to integer automatically and then use in you program
9th Jun 2019, 10:42 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 1
Each character has an ASCII and binary value. For example D = 068 or 01000100 E = 069 or 01000101 F = 070 or 01000110 G = 071 or 01000111 Maybe it has something to do with this? Show your code so we can check it out
9th Jun 2019, 7:06 AM
HNNX 🐿
HNNX 🐿 - avatar
0
Can you provide code which u tried?
9th Jun 2019, 7:08 AM
Yugabdh
Yugabdh - avatar