Summary: Expressions and Statements

I l @ ve RuBoard

Summary: Expressions and Statements

In C, expressions represent values, and statements represent instructions to the computer.

Expressions

An expression is a combination of operators and operands. The simplest expression is just a constant or a variable with no operator, such as 22 or beebop . More complex examples are 55 + 22 and vap = 2 * (vip + (vup = 4)) .

Statements

A statement is a command to the computer. Any expression followed by a semicolon forms a statement, although not necessarily a meaningful one. Statements can be simple or compound. Simple statements terminate in a semicolon, as shown in these examples:

 Declaration statement  int toes;  Assignment statement  toes = 12;  Function call statement  printf("%d\n", toes);  Control statement  while (toes < 20) toes = toes + 2;  Null statement  ; /* does nothing */  

Compound statements , or blocks , consist of one or more statements (which themselves can be compound) enclosed in braces. The following while statement is an example:

 while (years < 100) {     wisdom = wisdom + 1;     printf("%d %d\n", years, wisdom);     years = years + 1; } 
I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net