A byte-sized constant can be specified by giving its value in octal (base 8) or hexadecimal (base 16).
For example:
enum months {JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER};Something of this type can be assigned to one of the 12 constants given in the braces. (These actually have numeric values.)
You can use the const qualifier to indicate that a variable may not ne changed:
const double pi = 3.14159265358979; const char msg[] = "This cannot be changed\n";You can also use const for an array parameter:
int strlen(const char[]);but it is up the the implementation to determine whether this will be enforced.
Integer types are used with 0 being false and anything else being true.
Recall that logical expressions are evaluated left to right and evaluation stops as soon as the truth or falsehood of the result is known.
for (i=0;i<lim-1 && (c=getchar()) != '\n' && c != EOF; i++) s[i] = c;If the test i<lim-1 fails, the character will not be read in.
For binary operator like =, -, * and /, fi the operands are of different type, the smaller one gets converted into the type of the larger one.
Note that C does not allow more than one function with a given name.
You cannot have one version which takes an int parameter and another with the same name that takes a double parameter.
This assumes that the compiler has a prototype for the function available so that it knows to do the conversions.
int x,n; n = 5; x = n++;Will make n=6 and x=5 while
int x,n; n = 5; x = ++n;Will make n=6 and x=6.
Note that these cannot be applied to an expression: (i+j)++ is illegal.
& bitwise AND | bitwise inclusive OR ^ bitwise exclusive OR << left shift >> right shift ~ one's complement (unary)The first three of these are important for systems programming.
+= -= *= /= %= <<= >>= &= ^= |=Recall that an assignment operator has a value, and the value is the value assigned.
expr1 ? expr2 : expr3;First expr1 is evaluated. If it is true (non-zero) then expt2 is evaluated and that is the value of the conditional expression. Otherwise expr3 is evaluated and its value is the value of the conditional expression.
Associativity refers to the order used when the operators have the
same precedence.
Usually it is left to right except for the unary operators, ? and
assignment.
Some of these operators we have not yet discussed.