Vous êtes sur la page 1sur 2

The Type Cast Operator

The type cast operator has the effect of converting the value of the variable (2 to
type float for purposes of evaluation of the expression.
This operator does NOT permanently affect the value of the variable i2.
The type cast operator has a higher precedence that all the arithmetic operators
except the unary minus and unary plus.

The Assignment Operators
The C language permits you to join the arithmetic operators with the assignment
operator using the following general format: op=, where op can also be logical
or bit operator later in the course

_Complex and _Imaginary Types
Supported only by a few compilers
There are three complex types:
There are three imaginary types: An imaginary number has just an imaginary

Declaring Variables
Some older languages (FORTRAN, BASIC) aloow you to use variables without
declaring them.
Other languages (C, Pascal) impose to declare variables
Advantages of languages with variable declarations:
o Putting all the variables in one place makes it easier for a reader to
understand the program
o Thinking about which variables to declare encourages the programmer to
do some planning before writing a program

Declaration vs. Definition
Variable declaration: [Type, Identifier]
Variable definition; a declaration which does also reserve storage space (memory)

Lecture 3:

Program Looping Outline
o The for Statement
o Relational operators
o Nested for Loops
o Increment Operator
o Program Input
o For Loop Variables
Executing a program
o Program = list of statements
Conrolling the Program Flow
o Forms of controlling the program flow:
Executing a sequence of statements
Repeating a sequence
Program Looping
o Looping: doing one thing over and over
o Program loop; a set of statements that is executed repetively for a number
of times
o Simple example: displaying a message 100 time
Program Looping
o What if we have to compute the 200-th (1000-th, etc) triangular number 7
o In C: 3 different attachments for looping
Relational Operators
o The relational operators have lower precedence that all arithmetic
operations
o Do not confuse: the is equal to operator == and the assignment
operator =
o When comparing floating point values, only < and > comparisons make
sense
Increment Operator
o Because addition by 1 a very common operation in programs, a special
operator was created in C for this
o Increment operator: the expression ++n is equivalent to the expression n =
n+1
Program Input: Scanf, similar to printf: first argument contains format characters,
next arguments tell where to store the values entered at the keyboard More details
in a later chapter

Vous aimerez peut-être aussi