Adobe Scan Jan 14, 2024
Adobe Scan Jan 14, 2024
versions of the language that were are only 32 keywords andjts stiength lies in ts
built in
functions.
system developers
Toassure that the C
sim1lat but often
inccompatible. This posed a serious problem for
There
tions are available which can be used for developing
Cis highly portable. Thismeans thatC prograrns
prograrns
written for one
Several sandard fun.
computer can
(ANSI) language
appointed technical
sion of Cin 1989 a is
renmains standard, in 1983, American National Standards Institute to be
with ittle or ne modificatioD. Portability is important if we plan use a new computerrun on anohe
ards
committee
which now known as to define a standard for C. The committee approvcd a ver- ent operating system. wih adiffe
Organization
illustrated (1SO)
in Fig. 1.1.in 1990. The ANSI C. It was then approved by the International Stand-
standard was1999. The history of ANSICis
Clanguage is well suited for structured programming,,thus requiring the user to
proper collection of (these think of aprcblen
updatedIin in terms of function modules or blocks. A modules would
program. This modular
structure makes program debugging, testing and make a
Anotherimportant feature ofCis its ability to
extend itself.. AC
C library. We can continuously add
program
is nance easier.complete.
maintebasically
1960 ALGOL
International Group
of functions that are supported by the of
library. With the availability of a large number functions,
Before discussing specific features ofC, we shall
the
Jook at some
programming
our
task becomes
sample programs,
C
yacol ection
own funcions to r
simple
1967
BCPL and understand how hey work. and analyzL
Martin Richards
1.3 SAMPLE PROGRAM 1: PRINTING AMESSAGE K1
1970 B
Ken Thompson
Consideravery simple program given in Fig. 1.2.
1972
main( )
Traditional C Dennis Ritchie
/*.printing begins.....*/
1978
printf("I see, I remember"):
K&R C Kemighan and Ritchie ...printing ends.
1989 ANSIC
Fig. 1.2 A program to print one line of text
ANSI Committee
This program when executed willproduce the following output:
I see, I remember
1990 ANSUISO C ISO Committee Let us have a close look at the program. The first line informs the system that the name of the
program is main and the execution begins at this line. The main( ) is a special function used by the c
system to tell the computer where the program starts. Every program must have exactly one main
function. If we use more than one main function, the compiler cannot tell which one marks the begin
Fig. 1.1 History of ANSI C ning of the program.
The empty pair of parentheses immediately following main indicates that the function main has no
12 arguments (or parameters). The concept of arguments will be discussed in detail later when we
IMPORTANCE OF C t discuss functions (in Chapter 9).
The opening brace "in the second line
The increasing popularity of C is marks the beginning of the function main and the
whose rich set of built-in functionsprobably due to its many desirable qualities(It is a robust language brace ")" in the last line indicates the end of the function. In this case, the closing brace alsoclosing
marks
and operators can be used to
compiler combines the capabilities of an assembly language withwrite any complex program. TheC the end of the program. All the statements between these two braces form the function body. The
the features of a high-level lan function body contains a set of instructions to perform the given task.
guage and therefore it is wellsuited for writing both system
many of the C compilers available in the market are written software and business packages. In fact, In this case, the function body contains three statements out of which only the printf line is an
in C. executable statement. The lines beginning with /* and ending with */ are known as comment uie
(Programs written in C are efficient and fast. This is These are used in a program to enhance its readability and
powerful operators. It is many times faster than BASIC. Fordue to its variety of data types and executable statements and
understaning. Comment lines a
variable from 0 to 15000 takes about one second in C while itexample, a program to increment a therefore anything betweeD f* and */ is
eral, a comment can be inserted wherever blank spaces can occur-atignored
by the complel
takes more than 50 seconds in an the beginning, midaie ol ce
interpreter BASIC. a line-"but never in the
middle of a word ".
1.8 BASIC STRUCTURE OF C PROGRAMS
Theexamples discussed so far illustrate that aC programcan be viewed as a group of building blocks
called functions. A function is a subroutine that may include one or mnore statements designed to
perform aspecific task. To write aCprogram, we first create functions and then put them together. A
Cprogram may contain one or more sections shown in Fig. 1.9.
Documentation Section
Definition Sec:ian
Global Declaration Section
main () Function Section
Declaration part
Executatble part mam
Subprogram section
Function 1
Function 2
(User-defined functions)
Function n
Special Characters
& ampersand
^ caret
* asterisk
:colon minus sign
? question mark + plus sign
apostrophe <opening angle bracket
quotation mark (or less than sign)
2.1 INTRODUCTION !exclamation mark > closing angle bracket
|vertical bar (or greater than sign)
Islash (left parenthesis
Aprogramming language is designed to help process certain kinds of data consisting of numbers, \backslash )right parenthesis
characters and strings and to provide useful output known as information. The task of processing of tilde [ left bracket
ata is accomplished by executing asequence of precise instructions called aprogram. These in under score ]right bracket
Strucions are formed using certain symbols and words according to some rigid ruies known as syntax $ dollar sign { left brace
ries (or grammar). Every program instruction must confirm precisely to the syntax rules of the % percent sign }right brace
language. # number sign
LIke any other language, C has its own vocabulary and grarnmmar. In this chapter, we will discuss White Spaces
e concepts of constants and variables and their types as they relate toCprogramming language. Blank space
Horizontal tab
Carriage return
2.2 CHARACTER SET New line
Form feed
Lhe characters that can be used to form words, numbers and expressions depend upon the computer Table 2.2 ANSI CTrigraph Sequences
wcn the program is run. However, a subset of characters is available that can be used on most
personal, micro, mini and mainframe computers. The characters in Care grouped into the following Trigraph sequence Translation
categories: 29=
# number sign
1. Letters
??( [left bracket
2. Digits ??) Jright bracket
3. Special characters {left brace
4. White spaces } right brace
The entire character set is given in Table 2.l. | vetical bar
??/ \ back slash
The compiler ignores white spaces unless they are apart of a string constant. White spaces may be 9?/
to scparate words, but are prohibited between the characters of keywords and identifiers. ^ caret
ilde
24|
Programming in ANSIC Constants, Variables, und Data 'Iypes
CTOKLNS Rules for ldentiliers
apassge of lext, ndiv dual wous and unetuation
progtam the smallest nd1vdual unts are known
marks are called tokcas. Similarly, in aC
as C tokeus. I. irst character nust be an alphabet (or underscore).
Fig. 21.C programs are Chas six types of tokens as showin n 2. Must consist of only letters, digits or underscore.
written using these tokens and the syntax ofthe language. 3. Only first 31 characters are significant.
C TOKENS
4. Cannot use a keyword.
5. Must not contain wlhite space.
Keywords Constants
2.5 CONSTANrsB
Strings Operators
loat 155
Constants in Crefer to fixed values that do not change during the execution of a program. Csupports
while
100 "ABC" severaltypes of constants as illustrated in Fig. 2.2.
"year"
cONSTANTS
ldentifiers Spealal Symbols
main
amount
Fig. 2.1 Ctokens und examples Numerlc constants Character constante
2.4 KEYWORDS AND IDENTIFIERS
Every C
word is classified as cither a
and these meanings cannot be keyword or an identifier. Al keywords have fixed meanings Integer Roal Slngle character String
ments. The list of all keywordschanged. Keywords serve as basic constants
of ANSI Care listed in Table 2.3.building
constanta Constants constants
blocks for program state
lowercase. Some compilerS may use additional keywords All keywords must be written in Fig. 2.2 Basic (ypes of C constants
that must be identified from the Cmanual.
Table 2.3 ANSI CKeywords Integer Constants
wnbvoken ordes
auto
double An integer constant refers to a seguence, of digits. There are three types of integers, namely, decimal
break clse
int
struct integer, octal integer and hexadecimal integer.
long
Case
register
switch Decimal integers consist of aset of digits, 0through 9, preceded by an optional -or +sign Valid
char exterD typedef examples of decimal integer constants are:
return union
COnst
float short 123 -321 0 654321 +78
continue for unsigned Embedded spaces, commas, and non-digit characters are not permitted between digits. For exam
default signed void
goto sizeof ple,
do if volatile
static 15 750 20,000 $1000
while are illegal numbers. Note that ANSI C supports unary plus which was not defined carlier.
Identifiers refer to the names of variables, functions and An octal integer constant consists of any combination of digits from the set 0through 7, with a
consist of a sequence of letters and digits, with a letter asarrays. These are user-defined names and
a first character. Both uppercase and leading 0. Some examples of octal integer are:
lowercase letters are permitted, although lowercase letters are commonly used. The underscore char 037 0 0435 05S1
acter is also permitted in identifiers. It 1s usually used as a link between two words in long identifiers.
26 Programming in ANSI C
A
sequence of digits preceded by 0x or Constants, Variables, and Data, Types |27
include alphabets Athrough F or a through f.0XTheis letter
considered as hexadecinal integer. They may also
fractional parts like 17.548.Such numbers are called real (or floating point) constants. Further ex
15. Following are the examples of valid hex integers. A through F represent the numbers 10 through ämples of real constants are:
0X2 0x9F 0Xbcd 0x
We rarely use octal and 0.0083 -0.75 435.36 +247.0
hexxadecimal numbers in
The largest integer value that can be stored is programming. It is These numbers are shown in decimal notation, having a whole number followed by a decimal
and 2.147,483,647 on 32-bit
machines. It is machine-dependent. 32767 on 16-bit machines point and the fractional part. It is possible to ómit digits before the decimal point, or digits aflerthe
machines by appending qualifiers such as U,Lalsoandpossible to store larger integer constants on thése
UL to the
deoimal point. That is,
S6789U or S6789u
constants. For examples: 215. .95 -.71 +.5
987612347UL (unsigned
or 98761234ul (unsigned integer) are all valid real numbers.
9876543L long integer)
or
The concept of unsigned and long integers98765431 (long integer)
are discussed in detail
Areal number may also be expressed in exponential (or scientific) notation. For example, the
in Section 2.7. value 215.65 may be written as 2.1565e2 in exponential notation. e2 means multiply by 10. The
general form is:
Example 2.1| Representation of integer constants ona
l6-bit computer.
The program in Fig.2.3 illustrates the use of mantissa e exponent
Fig. 2.3 shows that the integer values integer constants on a 16-bit machine. The output in
larger than
However, when they are qualified as long integer32767 are not properly stored on a 16-bit
(by appending L), the values are correctlymachine.
The mantissais either a real number expressed in decimal notation or an integer. The exponent is an
stored. integer number with an optional plus or minus sign. The letter e separating the mantissa and the
Program exponent can be written in either lowercase or uppercase. Since the exponent causes the decimal
point to "float", this notation said to represent a real number in floating pointform. Examples of
main()
legal floating-point constants are:
0.65e4 12e-2 1.5e+5 3.18E3 -1.2E-1
printf(" Integer values\n\n"): Embedded white space is not allowed.
printf ("%d %d %d\n", Exponential notation is useful for representing numbers that are either very large or very small in
32767,32767+1,32767+10); magnitude. For example, 7500000000 may be written as 7.SE9 or 7SE8. Similarly, -0.000000368 is
printf ("\n"):
equivalent to -3.68E-7.
printf ("Long integer val ues\n\n"); Floating-point constants are normally represented as double-precision quantities. However, the
printf ("%1d %ld %1d\n", 32767L,32767L+1L,32767L+10L); suffixes for F may be used to force single-precision and l or L to extend double precision further.
Some examples of valid and invalid numeric constants are given in Table 2.4.
Output
Table 2.4 Examples of Numeric Constants
Integer values
32767 -32768 -32759 Constant Valid ? Remarks
Long integer values 698354L Yes Represents long integer
32767 32768 32777
25,000 No Commna is not allowed
+5.0E3 Yes (ANSI C supports unary plus)
3.5e-5 Yes
Fig. 2.3 Representation of integer constants on 16-bit machine 7.le 4 No No white space is permitted
-4.5e-2 Yes
1.5E+2.5 No
Real Constants $255
Exponent must be an integer
No
0X7B
S symbol is not permitted
Yes Hexadecimal integer
Integer numbers are inadequate to represent quantities that vary continuously, such as di_tances,
heights, temperatures, prices, and so on. These quantities are represented by numbers containing
28| Programming in ANSI C
Single CharacterConstants Constants, Variables. and Data
A single
a pair of character constant (or simply
Table 2.5 (Contd. ) Types 2
single quote marks. Examplecharacter
ofcharstant) contains a single character enclosed within Constant
Meaning
X constants are: vertical tab
Note that the character constant single quote
Space. 5' is not the same as double quote
the number 5. The last
Character constants have constant 1S a bla question mark
integer values known as ASCII values. For example, the "\0
backslash
null
would print the number printf
97, the
("%d", 'a'): statement
ASCII value of the letter a. 2.6 VARIABLES i:.DigoRT
Similarly, the statement
would output the letter printf("%c", "97'):
'a'. ASCII values for all
Since each characters Avariable is a data name that may be used to store a data value. Unlike
are constants
operations on character constant given in Appendix that
character constants.represents
1I.
differentremaitimesn
an integer unchanged during the execution of a program, a variable may take different values
They are discussed value,
it is also possible to perform at d
in Chapter 8. arithmetic during execution. In Chapter 1, we used several variables. For instance, we used tthe
variablethe amount
in Sample Program 3 to store the value of money at the end of each year (after adding
String Constants earned during that year).
t
A string A variable name can be chosen by the programmer in a meaningful way so as to reflect its fune:
constant is a
letters, numbers, specialsequence of characters enclosed in double quotes. The characters may be or nature in the program. Some examples of such names are:
characters and blank space. Examples are: Average
"Hello!" "1987" "WELL height
Remember that a character constant (e.g., 'X)DONE" «?...!" 5+3" "X"
is not equivalent to the
Total
constant (e.g., X"). Further, a single character string single character string Counter 1
value while a character constant has an integer constant does not have an equivalent integer class_strength
value.
build meaningful programs.
Manipulation of characterCharacter strings are often used in
strings are considered in detail inprograms
Chapter 8.
to As
ter,
mentioned earlier, variable names may consist ofMetters, digits, and the underscore )charae.
subject to the following conditions:
Backslash Character Constants 1. They must begin with aletter.
R P m i t underscore as the first character
2. ANSI standard fe&& characters.
Csupports some special backslash more than eight characters, since only the first eightHowever, length should not be normally
the symbol '\n' stands for newline character constants that are used in output functions. For example, characters are treated as significant by
character. A list of such backslash character constants is given in
many compilers.
Table 2.5. Note that each one of them represents one character, although they consist of two charac 3. Uppercase and lowercase are significant. That is, the varible Total is not the same as total or
ters. These characters combinations are known as escape TOTAL.
sequences. 4. It should not be a
Table 2.5
keyword.
5. White space is not allowed.
Backslash Character Constants
Some examples of valid variable names are:
Constant John
Meaning Value T_raise
\a' Delhi xl
audible alert (bell) ph_value
back space mark sum1 distance
\f form feed
n new line
Invalid examples include:
\r
carriage return 123 (area)
horizontal tab % 25th
(Contd,) Further examples of variable names and their
correctness are given in Table 2.6.
discuss
describetended
(Moat),
pointingand types C 2.3 without
selectstants TYPES mean If
TheDerived 2. ANSI language
DATA only 30
All
pointers
are 3. 1.
thdiffer
e the averagc_number PriceS charVariablename
int_type groupone First_tag
User-defined dataPrimary the
data Cprimarytypes changing
brietlythem compilers
types
defined C
type
supports from is
same
first Programning
are rich
cach are appropriate thing eight
discussed data types
data (or
double-precision in machine in their
given suchsupport fundamental)
thtypes
e three tocharacters
one its
as next data htaverage_height
meanings. average_weight
avg the
of in long five as and classes to to average_height in
them Fig. computer. Table
section the types.
int
and
their
machine. Valid
are Valid valid
Not valid
valid
Not Not
Valid Valid ? ANSI
fundamental
in2.4. data needs
when of and and recognized 2.6
and
this floating
The
while
extensions data Storage Such C
types ofThe
section. long they
types: the wt avg
Examples
range t he _average _weight names
double.point dataderived are representations
variety
applicaion by
encountered.
of are
types, can a of
(double)
the discussed of compiler,
Various data data be Varnable
basic nanmely rewritten
as Keywordeight
First Dollar char isRemark
Blank a
types types
well and
four data and in
then Names
integer such this machine
available space sign
void. as as the keyword
typestypes the may
section.
as tsígnificant
wcharacters
o are
is
is
Many
are and (int), arrays, machine.
instructions names
be illegal
not
allow part
the
given character permitted
of The
terminology them functions, the of
in user-defined programmer to narme
a
Table (char), also handle
structures
2.7.usedofter
float data con
We ex to
to
bts) Integer
Types
he
size the
ofSize
te Table
otaiger
fcat
nteger
doubiefloet Das
ype
2.7
Size
sie
cEn be
Rage
epewt
steensn
NIE e
he f
rage B
Dae
-
Tgs
-hac
16
Mae
s-
C without mean Ifonly 30
describetended pointing
discuss andtypes selectstants
language average_ char Variable
numbergrouponePiceSFirst_tag
int_type name
All The 3. 2. 1. ANSI the
pointers the
data
briefly them compilers defined
User-defined
C
ar
primarye Primary
Derived
C
tdiffer
h e TYPES
DATA changing
their same
first
Programming
(float), type
supports from is
types are thing eight
appropriate rich
each are discussed data data (or machine
in in
double-precision
given such support fundamental)
thetypes datatypes three its
to characters
one wt_average
ht_average
meanings. average_height
and average_weight
avg the
as next data
computer. Table in
of in types classes
them Fig. long five section as and to to height ANSI
and their machine.the types. are ValidValidvalidNotvalid
NotValid Valid ?
Notvalid
int 2.6
infundamental
2.4. when data needs
of Storage and recognized C
this floating and while
extensions data Such
Exanmples
The types ofThe avL
section. long they types: the names
range th e representations
variety
double.point data derived are applicaion weight by
encountered. are can a of
of types, of compiler,
(double)
the discussedthisin be
Variable
Various data data
basic namely rewritten Keyword FirstBlank Dollar char Remark
as
types and
types well then
four data and eightspace sign is Names
machine a
integer
void. such available as as th e may
keyword
typestypes the twocharacters is is
section. as
Many(int), machine. be illegal
not
are andcharacterfunctions,
structures
arrays, instructions
allow
names part
permitted
given the of The ofare
terminology them user-defined the a
in
significant
name
programmer to
Table (char),
also float handle
bits)Integers Integer
Types
integer tude as defines
For of wordSigned theintegers
example, a integer In size the
regularof orderlength
these integer occupy
numbers the ofsize are
number int
storage, to th e whole Table
can of longint shortint signed
int
shorttypesprovide uses integer flo¡t
will
number store integeranone
namely numbers double float int char Data
type 2.7
and int so one word
be that some anvalue
represents bit Floating
point
Type
from areuses. they integer that of Size double Integer
short
control for
always
Unlike iscan with
storage, and
0 can sign
limited Fig.
to int, ranging be a
65,53S. fairly be Range unsigned' t unsigned
inunsigned
longshort
unsigned int int PRIMARY
TYPES
DATA
positive. Qver and stored and range 2.4
signed organized int, double
Long Integral
Type
small and the from 15 to
bitsdependsthe since of Primary
of type
integers,
Therefore, integer range values Basic
-2,147,483,648long forange
r the Constants,
from data
int, of -32768 the word Data
supported
on
unsignedvalues thnumbers e magnitude the typès
in sizes
for smallest both Types Variables,
computer. -32,768
32,767
3.4ete38
3.4e-38
1.7e-308
1.7e+308 to to to Range
127 to of
-128 in
a and to of C char char
charsigned
integers l6 signed and to
+32767machines by on
unsigned
birequires
t 2,147,483,647.
to
storage of a Character
the the particular 16-bit void
machine, If values and
use largest, and number. (that we
Machines Data
all halfunsignedspace,C use vary
the the the as is, machine.
a
(typically,
-2 16 Types31
bits shown Similarly,
range amount has bit
for forms.three to
word
ofthe
ofFig.in +2-1). Generally,
unsigned
magnistorage classes ANSIC alength, 16
32 or
2.5. bit A 32
bits.
precision
but double
providedFloating
ofTypes
Floating
Point
The with precision. double
long
double floatlong
unsigned int long
signed int longshort
intorsigned the on
unsigned ishort
nt unsigned
inshort
t inor
t unsigned
int intchar char Type
data integers
allowed We 32|
relationship a or
numbers.
greater bypoint or declare
signed
typeFloatinga signed
float (or combinations is Programming
precision. number
Remember number real) int Table optional long
among char
point
numbers and
uses 2.8 because
floating To numbers is unsigned
extend that 64not of
are Size basic in
Fig. double bits
sufficient, the ANSI
types the stored and types
2.6 giving are integers
default
precision (bits)
Size
Floating-point double
long is type defined in 80 64 32 32 32 Range Fig. C
double
illustrated 32 8 1616 and
float the declaration to
represents
precision type a bits qualifiersincrease 2.5
of longint shortint
further, in(on Data int
Integer
double C
types in byall assumes the
Fig. wethe of the16bit Types and
14can range types
2.6. may samedigits.keyword 3.4E 1.7E 3.4E
-2,147,483,648
2,147,483,647 their
4,294,967,295 to0 to 255 -128
to0127 to -32,768
32,767
65535
255-128
to0127 to
to0 to Range. on
be and signed of
a
use data -308- - a size values.
used 32 4932 38 16-bit
long These bit and
type float. to
to
number.
to
machines), Machine range The
to 3.4E
double that define are 1.1E
!.7E
When + use
known
float + 38 on
Table
+ of
which the 4932 308 a
represents, number.
the with l6-bitqualifier
as 2.8
accutacy
uses double 6
digits machine.shows
80 signed
A
all
follows:
ablesas ype User-Defined
type. datidentifier;
Remember a typedef Declaration
variables.
represent Type
ful batchl
element feature aC
supports
Here, Where
data Some type.
want
Similarly,
below:letter shownfault
below: Integer
type and
floating units The type an 1.23456789L -1.2f1.234 12.0 Literal
0 987654UL 45678U
-56789L -222 +111
Literal
exämples that It
names batch2 takes
existing fthe by
symbolizes the refers
existing or constants,
specifying
point the resulting
floating
F
are new known to
for typedef
units;int of to general data the
array marks batch2;
batchl,
units typede
increasinginclared type type data an
int existing
type
is
type. as number datapoint unsigned by
variables. definition
f formn: "type default,
name1 and 'new' The
as float may constants,type Default
the int [50] marks data definition" Type for Type
only user-defined double
long double
double float double
double unsigned unsigned
to longint long
int int int int
representor
readabilityvariable The marks; are: belong type float be long values
, in
main name2 symbolizes name, and andfloat
by
to default after
advantage and "identifier" any that int Constants,
of
of [50]: but data letter or the type
the class allows Constants
namel[50] not long number
float. type represent
program or data.
oftypedef the of users double,
They type,
data refers identifier L
for (by We Variablésy
and can type. to long double
including to define we appending can
name2{50] 1.23456789 -1.21.234 12.0 0.0 0.Value
0 45,678 -222 111Value
-56,789
9,87,654
is be the can double must
that typedef type override and
later "new" later an
we the identifier append data. Data
can are used
user-defined
cannot name be as U
shown orthis Types
create to used If L)de
declared the
declare create given that we as
to
meaning declare would
as a to
vari new ones. the 35
50
variablesVariables
their
2.9 ple that constants.
example:Forever,stants. Anexample The Thedefinition, can The enum tollowN an
Theconstant
increase Here,the The 36
location the That assignments
enunnerated "identifier"have Anohet
definition identifier
DECLARATIONare in automaticcompiler
is, we
one rogranming
recognized. and can C Nuccenively
the can theof
uner
visibility. have and automnatically
enumeration ansigns variables of is
(valuel, deined
Monday ansignments
is the declare values a
matn) int n declaration
{Monday,
enumday uNer
/* not enum weekend week enum enum valuel;
Iriday:
1f value3i
v5 vl
following enum
Consider by1 Saturday week(week
ed deinedvaluel, data
Example The only st day day vl, vaiablesenclosed in
day 1dent type
stornge data OE
the
assigned
of (Monday
constnnt
can st -
week types
v2, ANSI
Nonday: (Monday, enumented ..
following
of enumeratcd be - ifier
vn within to valuen)ienumerated is
type overidden C
storage classSTORAG the valuelintepgerTuesday) st, are cAn be
valid vl, of
decides
but value 1, week
uesday, only thin the
example: also variables Tuesday, nNNgned in digits v2, 'new'braces data
Sunday) of by end; have data
closses storage type
CUASSpthe The 1. aswigning beginning .. one (known
ype which type
portion week remaining can Vn j
/ clusNx be value2
0, Sunday} of an puovided
values with the below ascAn
ofthat st,combined Sunday}: values enumeratlon
the is ) be
provides week constants explicitly annigncd to uned
by
program wluel, ANSI
end; in all to
one the declare
constants). Atandad
information
within statement.annignedare the
to I,con
enuneration and value2,
enumeration so variables
which on.
Exam valucn . Aler n
about How valuen detned
the
this that
right tconst
_hand he ple: can We trates#define
been statementstants
int achieve may PRICES
#define
100#define
ARRAY
#Define 11 25; #define
#define N #2.X=
5
Statement
44|
8. 7.
1.Symbolic
is define 5. 4. 3. 2.
variable a mentioned
some 6.
like program #detine
Constant.
Symbolic After by
#define #must name A
lowercase
CAPITALS NoSymbolic (not
of new
sidean statement
DECHÄRINGANÁRIABLEAS this the To NMAX
invalid using blank blank which Programming
data 5, definition, and variables),
class_size by
value M names
type declaring 10 10
here.statements
(the
names
statements
an space
the
be
space define
assignment statements is assignment the letters. names
const of Table usual
a constant. to are
qualifier More
preprocessor is
first visually
certain
are the between they
a 3.14159#define
#define PI200MAX
must practice may mustrequired havesometimes
This symbolic
int the 2.11 advanced symbolic character
of#define. NOT
is the
do in
statement definednot variables
variable appear statement. not distinguish
only not
class_size Invalid
Invalid
Invalid
Invalid
Invalid
the ANSI
endbetween pound
be Iavalid
Validity
Examples isdeclared
name samne appearcalled
constant.
modified by compiler to in a
with to types anywhere
place with conventiun,
the C
like ANSI remain For
should them form
#define line. sign constant
in
any = the of directive ofthem for
example,
semicolon.
a
declarations.
as
by 40;qualifier Invaliddefinitions from
otherstandard. constant data not #variable
the in in and and not
program. the the types. be the identifiers.
variable. define A No STRENGTH=200;
and
program assigned symbolic the normala
This const
during symbol S No'=' #define
Remark beginning
will rule.)
statement word names.
semicolonwhite sign is Its The
tells at should much
be
However, the the is but
data any define variable following Since
the is space Statements
not
discussed of name (Symbolic
time
execution not
be
can more before
the type other
compiler at
allowed
permitted efineinbetween isnames, the
of the program). and
it powerful depends value permitted. symbolic
rules
can initialization. lowercase end later. it is between
that of only is illegal. names
be within which apply
a in # Tablereferenced
used the program. and than' on
nameletters one names
value define 2.11what the the the are are to
on name. written
Exam type program symbolic written a
the of We illus has in #detine are
the of con
in in
care
results.
constant.C an pointProblem
normally type other well. examine has hand example:For ANSI
Remember Just tooverflow Integers
4OVERFLOW to Remember The variable's
a
define
(Overflow values process, changed
If DECLRIÑGR 2.13
hold. of side
results we value standard
are the
ED E E A Ao correct doeswhich are The data wish of
not always then th evalue an of value
double,
Floating
unsigned, Integer All or Each Do Use Dobecause Use rounded in overflow
largest that
function. programs. Do normally is th e that value.assignment date defines
variables meaningful not not only data provide a we the of
variable not seriousexact largest the may
constants, create volatile may value the may
we
point use many use types value
off occurs value variable volatile date;
int be
must we 31 the produces any within another
keywords possible to declare be changed
constants must must variable used or or problem
fwarning ANDINED the thatwhen must of statement.
underscore of a altered
append and less the handling the number a const variable
append by be must each qualifier
initialized intelligent
default, characters
identifiers a limits realvariable the the not fBREAS
YOLATIpe at
default names or negative or may by
the be any value variable
int be timeWhen some any
the declared system as indication
the occursignificantvalue, of modified declared
letters
that the
of can time
volatile
assume
letters input/output the of location it
to before varizble
names. for in number.) whereas hold a as is
externalwe
double. differ first if
rangc by
For
fo r identifiers. the
library th e variable both encountered as declare some that
L character of also by
L and int they its only
system integer data ofdigits volatile
the could Constants,
to Totypes. We an const
= factors
U type names values. the depends external
the make are by underflow
type is 100;program a
numbers them. To
to
used atone Thislibrary of should integral
overflow. allowed either and can variable to be
the for identifiers does see even used
them make or helps start ontoo volatile be sources Variables,
in identifiers.
beginning therefore while whether
modified
to the two not data
results (or the bi g as if to
the ensure with It it tell
denote program. machine. or
letters. (or simplymatchtypes specified), as it volatile, does (from
explicitly
numbers underscore. exercise in too shown may
of portability variable by any not and
float the gives theused. zero. small be its outside
Since external appear
the Data
or long program value an altered own
below:
names) incorrect aHowever, fo r çompiler th e
long greater overflow floating the programa thcomni
e l Types
of on
or of by alteratio th e nr
the data som: laf