I've read similar questions and answers for code in C++ and just wanted to confirm my understanding.
For the C code below;
#include <stdio.h>
int main(void){
int a, b, c, d;
a = scanf("%d%d%d", &b, &c, &d);
printf("Number of values read: %d\n", a);
printf("Values read: %d %d %d", b, c, d);
return 0;
}
If input is 0 A 0
,
My output is;
Number of values read: 1
Values read: 0 0 4200544
Is the following explanation correct?
scanf
expects data type int
but gets char
as input. Thus, it stops reading and returns a value of 0.
Only 1 value was accurately given as input, so number of values read: 1
2nd int
is assigned value 0. The last int
var is unassigned, so when printed, it returns garbage values.
Is there a better explanation? I just want to make sure that I have a correct understanding of why the output is as such.