printf() is the C function for writing to the standard output (normally, the console, but not always). It takes a C string that tells it what to write and what other parameters, if any, it will receive.
Example:
printf("2+2=%d\n",2+2);
This will print "2+2=4" and will advance the cursor to the next line.
'\n' is what is known as an escape character. It's used to represent special characters in string literals. The most commonly used are:
\n - New line
\t - Horizontal tab
\\ - Backslash
\0 - Null character
Escape characters are not particular to printf(). They are part of the C syntax.
"%d" is a special sequence that gives printf() information about the parameters that are being passed to it. In this case, it's telling it that the parameter in question is a signed (i.e. can be positive or negative) number. There's quite a few of these:
%d - Signed integer
%u - Unsigned integer
%f - Floating point number
%c - Character
%s - C string
%x - Unsigned integer expressed in hexadecimal with lower case characters
%X - Same as above but with uppper case characters
I can't explain all the things that can be done with printf(). If you're interested, you can check the reference:
http://www.cplusplus.com/reference/clibrary/cstdio/printf.html
As for operators, it's easier to explain with examples than in words:
1 2 3 4 5 6 7 8 9 10 11 12
|
int a=5;
int b=++a;
/*
a now equals 6.
b also equals 6.
*/
a=5;
b=a++;
/*
a now equals 6.
b now equals 5.
*/
|
The prefix operator (++a) first increments the variable, and then assigns the incremented value, while the postfix operator (a++) assigns the unincremented value first, and then increments the variable.
It's possible to write books on boolean operators, so I'll just give you a very brief summary:
T is true and F is false
a b a && b
F F F
F T F
T F F
T T T
a b a || b
F F F
F T T
T F T
T T T
Relational operators compare to values:
a==b returns true if a equals b
a!=b returns true if a does not equals b
a<b returns true if a is lower than b
a>=b returns true if a is greater than or equal to b
a<b returns true if a is greater than b
a>=b returns true if a is lower than or equal to b