Node:Expressions, Next:Parentheses and Priority, Previous:Expressions and values, Up:Expressions and operators
An expression is simply a string of operators, variables, numbers,
or some combination, that can be parsed by the compiler. All of the
following are expressions:
19 1 + 2 + 3 my_var my_var + some_function() (my_var + 4 * (some_function() + 2)) 32 * circumference / 3.14 day_of_month % 7
Here is an example of some arithmetic expressions in C:
#include <stdio.h>
int main ()
{
int my_int;
printf ("Arithmetic Operators:\n\n");
my_int = 6;
printf ("my_int = %d, -my_int = %d\n", my_int, -my_int);
printf ("int 1 + 2 = %d\n", 1 + 2);
printf ("int 5 - 1 = %d\n", 5 - 1);
printf ("int 5 * 2 = %d\n", 5 * 2);
printf ("\n9 div 4 = 2 remainder 1:\n");
printf ("int 9 / 4 = %d\n", 9 / 4);
printf ("int 9 % 4 = %d\n", 9 % 4);
printf ("double 9 / 4 = %f\n", 9.0 / 4.0);
return 0;
}
The program above produces the output below:
Arithmetic Operators: my_int = 6, -my_int = -6 int 1 + 2 = 3 int 5 - 1 = 4 int 5 * 2 = 10 9 div 4 = 2 remainder 1: int 9 / 4 = 2 int 9 % 4 = 1 double 9 / 4 = 2.250000