+ 2

Initializing Var with Scanf()

Why is this not working: long int input = scanf("%ld",&input); Is it forbidden to define a var this way?!

18th Jul 2020, 11:18 AM
Oliver
4 Antworten
+ 1
scanf("%ld", &input); is fine, but long int input = scanf("%ld", &input); makes you get an value you don't expect. You can do: long int input = 0; scanf("ld", &input);
18th Jul 2020, 11:38 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
I am not sure about this, but I reckon that you can’t use the word input as a variable name. probably a reserved name. several languages have this
18th Jul 2020, 11:22 AM
Brave Tea
Brave Tea - avatar
0
@Brave Tea Nope - thats not the case
18th Jul 2020, 11:38 AM
Oliver
0
Yep, i know. The question is: why?
18th Jul 2020, 12:01 PM
Oliver