This formal declaration of variables is done in the following manner:
;
For example:
int a = 0;
where an integer (normally 4 bytes) is declared in memory with a name of a and an initial
value of 0.
Once declared, the assignment construct is used to change the value of a variable. For
example, the statement:
x=x+1;
is an assignment statement containing a variable x modified by the + operator. The new
value is stored into x. It is common to use the format:
destination = source
where destination is where the final outcome is stored.
printf
The C language comes with many useful constructs for free (bundled in the libc library).
One of the most commonly used constructs is the printf command, generally used to
print output to the screen. There are two forms of the printf command:
printf();
printf(, );
Chapter 6: Programming Survival Skills
123
PART III
int Stores signed integer values
such as 314 or ??“314
4 bytes for 32-bit machines
2 bytes for 16-bit machines
float Stores signed floating-point
numbers; for example, ??“3.234
4 bytes
double Stores large floating-point
numbers
8 bytes
char Stores a single character such
as ???d???
1 byte
Table 6-1
Types of Variables
The first format is straightforward and is used to display a simple string to the screen.
Pages:
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277