Why do I get this strange outputs? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why do I get this strange outputs?

Where do the output numbers come from when I input something else other than a decimal in the last example ? : #include <stdio.h> int main() { int a, b; printf("Enter two numbers:"); scanf("%d %d", &a, &b); printf("\nSum: %d", a+b); return 0; } Input1: 2, Input2:y ⇨ output

2nd Nov 2018, 11:06 PM
Ludo
Ludo - avatar
1 Answer
+ 5
You should link your code by using the plus in circle icon or the share to copy it's link to the clipboard and pasting it here. That way we can run your code as is. In your case, y isn't a number so b remains with the value left in memory from before your function gets run. You should always initialize your variables.
3rd Nov 2018, 12:57 AM
John Wells
John Wells - avatar