The following is a simple C program:
#include <stdio.h>
int main(void)
{
//Question 2.16
//Variables that will be used to store the two numbers
int num1;
int num2;
//Message to prompt the user
printf ("Enter two numbers\n");
//Accepting the users input
scanf("%d %d" , &num1, &num2);
if (num1 > num2) {
printf("%d is greater\n", num1); // Print num1 if num1 is greater
}
else { //Otherwise print that num1 is not greater
printf("%d is not greater\n", num1);
}
return 0; // End of program
}
But when I build and run the program (the IDE that I am using is Eclipse Cpp Neon), I have to input the values for the variables num1 and num2 before the first printf statement is executed. See the following for the console output:
2 5 Enter two numbers 2 is not greater
My question is simply this: Why is this happening? Any explanation would be welcome.