I'm new to C language. Here's the code I used to get input for a and b and print them. But I did not get the values I entered via the terminal can you explain why I got different values for a and b?
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int a,b;
scanf("%d, %d", &a, &b);
printf("%d, %d", a, b);
return 0;
}
I entered 5 9 as inputs, but I got 5 and 16 as outputs.
scanf's return value."%d, %d"tellsscanfto expect an integer, a comma, and an integer. When you run the program, are you typing a comma between5and9?scanf, you'll find that it returned 1, indicating that it was only able to read 1 of the two values you requested. 16 was simply a random value which the uninitialized variablebhappened to start out with. If you change the declaration to something likeint a = 77, b = 88;you'll be able to see what's going on more clearly.