Code:
//Printf and Scanf syntax
//Include c libraries
#include <stdio.h>
//Define main function
int main (void)
{
//Declare local variables
int a, b, c;
//Request integer and character values, and print to screen
printf ("Enter first integer: ");
scanf ("%d", &a);//& is a "Pointer" and is being used to assign this integer to memory
printf ("\n%d", a);//After pointer above has assigned integer to memory, the variable has been initialized so it is used here to identify the scanf input that is called
printf ("\n\nEnter second integer: ");
scanf ("%d", &b);
printf ("\n%d", b);
printf("\n\n%d %d", a, b); //Note that \n can be added for each additional line needed
printf ("\n\nEnter a character: ");
scanf ("\n%c", &c);
printf ("\n%c", c);
printf ("\n\n%c %d %d", c, a, b);
printf ("\n\n%d %c %d", b, c, a);
return (0);
}
1) My understanding of "&" (e.g., line 14) is that it is a pointer and in this context is used to initialize variable a; correct?
2) I have not studied the use of "%" so am contextually figuring out how this works. So far, I understand it to be used in conjunction with scanf to capture user input, and with this in mind have defined "%c" as used for characters, and "%d" as used for digits. Is this a fair beginner assumption?
3) Why do some lines require a double "\n" to effect single line spacing? For example, I use one "\n" in line 15 to get single spacing, but in the next line 16 I have to use double "\n" to get the same spacing in command line output.
4) C libraries such as #include <stdio.h> tell the compiler to pull code for functions such as printf and scanf. Without these library declarations the compiler wouldn't know what to do with such functions; correct? And is it correct to call printf and scanf functions?
Thank you everyone.