I'm new to c++ & its developing I used to scan to take input parameters. But I gave two input parameters. But program allows me to enter extra parameter. Please explain me why this happened. Please find below the code I I used.
#include <iostream>
int main(int argc, const char * argv[]) {
int a,b;
scanf("%i %i ",&a,&b);
printf("a-> %i",a);
printf("b-> %i",b);
return 0;
}
Output (40 is allowed as an extra parameter)
20
30
40
a-> 20b-> 30Program ended with exit code: 0
You have a space in your format after the second %i.
scanf
will read extra data to match the space. Remove the space and it should work as you expected.