Professional Documents
Culture Documents
Lecture 4 PDF
Lecture 4 PDF
Lecture – 4
C keywords
There are certain reserved words, called keywords, that have standard, predefined meanings in C. These
keywords can be used only for their intended purpose; they cannot be used as programmer-defined identifiers.
The standard keywords are
do register void
double return volatile
else short while
enum signed
Some compilers may also include some or all of the following keywords.
2.6 DECLARATIONS
C variable declaration
A declaration associates a group of variables with a specific data type. All variables must be declared
they can appear in executable statements.
• A declaration
A declaration consistsassociates a group
of a data type, of by
followed variables withvariable
one or more a specific
names, data type
ending with a sem
(Recall•that
All the permissible
variables mustdatabetypes are discussed
declared beforeinthey
Sec.
36 2.3.) Each array
can appear in variable
executablemust be followe
CF
pair of square brackets, containing a positive integer which specifies the size (i.e., the number of eleme
statements
the array.
• A declaration consists of a data type, followed bydeclarations
These one or more could also have been writte
variable names, ending with a semicolon
EXAMPLE 2.21 A C program contains the following type declarations. i n t a ;
i n t b;
int a , b, c ; i n t c;
f l o a t r o o t l , root2; float rootl;
char f l a g , t e x t [ 8 0 ] ; f l o a t root2;
char f l a g ;
char
Thus, a, b and c are declared to be integer variables, r o o t l and r o o t 2 are t e x t [ 8 0 ] ;variables, f l a g is a ch
floating-point
variable and t e x t is an 80-element, char-type array. Note the square brackets enclosing the size specification for t e
short i n t a , b, c;
char f l a g ;
long i n t r, s , t ;
char t e x t [ 8 0 ] ;
int P , 9;
C variable declaration
This form may be useful if each variable is to be accompanied its purpose.
by a comment
Some compilers explaining
will allocate less storage space toInth
however, items of the same type are usually combinedandinq.a single declaration.
Typical values are two bytes for each short inte
• A declaration associates a group of variable.variables Thewith a specific
maximum data
permissible type
values of a, b and c
Integer-type variables can be declared to bewhenshort integer
using for smaller
a compiler integer quantities, or lo
of this type.
• All variables must be declared before they canallocate
larger integer quantities. (Recall that some C compilers
appearless in executable
Similarly, some compilersstorage spaceadditional
will allocate to short
statements
additional storage space to long integers.) Suchinteger
variables are declared
variables by writing
p and q. Typical valuess hare
o rtwo nta
t i words
• A declaration
or simply s h o r t and lconsists of a data type,
o n g , respectively. for followed by integer
each ordinary one orvariable.
more The maximum per
variable names, ending with a semicolon permissible values of p and q when using one of these co
EXAMPLE 2.22 The above
A C program contains the following type declarations could have been written as
declarations.
short i n t a , b, c; short a, b y c ;
long i n t r, s , t ; long r, s , t ;
int P , 9; int P , 9;
to thesshort
Some compilers will allocate less storage spaceThus, h o r t integer r t i n t are, bequivalent,
and s h ovariables long
and c thanastoarethe int
and q. Typical values are two bytes for each short integer variable, and four bytes (one word) for each
Input: scanf function
• Performs input from keyboard
• It requires a format string and a list of variables into which the value
received from the keyboard will be stored
• format string = individual groups of characters (usually ‘%’ sign,
followed by a conversion character), with one character group for
each variable in the list
int a, b; Variable list (note the &
float c; before a variable name)