Page 1 :
z, , Se are eee serene et, , Constants, Variables,, , and Data Types, , , , 2.1) INTRODUCTION, , , , oxramiming language is designed to help process certain kinds of dala consisting of, bers, characters and strings and to provide useful output known as information. The, of processing of data is accomplished by executing a sequence of precise instructions, called ap rogram.) These instructions are formed using certain symbols and words according, ome rigid rules known as syntax rules (or &rammar)) Every program instruction must, , , , , , , , , to, rm precisely to the syntax rules of the language. — /, Like any other language, C has its own vocabulary and grammar. In this chapter, we will, , iscuss the concepts of constants and variables and their types as they relate to C program, , , ming language. } : :, , ae! |, , ‘The characters that can be used to form words, numbers and expressians depend _upan the, , “Computer on which the program is run.JHowever, a subset of characters is available that can, Bf kad Go Fast cape es mini and mainframe computers, The characters in C are, grouped into the following categories:, , XX Letters :, , Eo Digits . ;, — a Special characters/ ¢ Wie bs, CA. White spaces 7, The entire character set is given in Table 2.1., , Sass, ttf, , 22) (CHARACTER SE
Page 2 :
2b |- a ——~—— . Progratnming trv ANSI C, , Trigraph Characters, , any non-English keyboards do not support all the characters mentioned in Table 2.1. ANSI, ce introduces on oe of “wien ont to provide a way to enter certain characters, , Each trigraph sequence consists of three charac, , 5 A another che as shown in Table 23., For ‘examples, ifa ent does not support square brackets, we can stil] use them in a, , program using the trigraphs ??( and ??)., Table 2.1 C Character Set, , , , , , , , , , , , , , , , , , , , , , , _ belles: ese Zs 5 Digits, — A ai : . All decimal digits Ow, Lowercase — —, Special Characters, | —-—— —, ,comma —-— &ersand |, “period -- “*caret, ‘semicoluu - : * asterisk, :cofon — minus sign, ? question mark + plus sign, * apostrophe , < opening angle bracket, * quotation mark a : _for less than sign), ! exclamation merk > closing angle bracket, vertical bar ‘ dl ~~ (or rgéeater than sign), /slash z xs (left parenihesis, \ backslash ) right parcithesis_, ~tilde . [left bracket, a _under score ] right bracket, $ dollar sign . (left brace, Y%percentsign ss __ } right brace, # number sign, White Spaces, Blank space. =f, - Horizontal wb fs ., Carriage retum V7) Co}, 7 New line, Form feed a, , , , Table 2.2 ANS! C Trigraph Sequences, , , , , , ne ¥ # number sign, , 1% [left bracket, , ” J right bracket 3, “N< { left brace, , t> } right brace, , ™ -|vetical bar, , MW \back slash, , 2. A caret, ‘7 ~tilde, , , , , , , ee renter orton slate « eneRty alse OI 2% 1, , , , , , Ce
Page 4 :
ah — ~~~ —— Programming in ANSI C, letters are cammar, , uppercase and lowercase letters are permitted, although lowercase med ago, , « {, used(The underscore character 1s also permitted in identifiers [tis usual!, n long identifiers, P, , two wards, Rules for Identifiers, , , , 1, First character must be an alphabet (or underscore)., 2. Must consist of only letters, digits or underscore, , 3. Only first 31 characters are significant., 4, Sa, , Prete, , _J25] constants 2 phir with « fry, , , , Constants in C refer to fixed values that do not change during the execution uf a prog, Supports several types of constants as illustrated in Fig, 2.2, , [ constants, \ Numeric constants |, , , , , , , , , , , , , , , , , , f, i \, Integer Real Single character —, constants constants constants Lonstants, , Fig. 2.2 Basic types of C constents, , (eateger Constants), integer constant refers to a sequence of digits. There are three types of integers, namely,, , decimal integer, octal integer and hexadecimal integer}, Decimal integers consist of a set of digits, 0 through 9, preceded by an optional - or + sign., , Valid examples of decimal integer constants are- ', : 123-321 0 654321 +78, , Embedded spaces, commas, and non-digit characters are not permitted between digits, , For example,, 15750 20,000 $1000, , are illegal numbers.
Page 5 :
aly, , \, , , , 7 | 27, , trary ive i fined carlier., Note ANSE C supports which was not de earlier., Bi Sn consists of any,combination of digits trom the set 0 through 7,, , etal intepercans! Sean, Liv. «() Same exam of pgtal integer are._, ivading ) Same exampre: NOs O 04350551, , A equeace of digits precedes by Ox ur OX ixconsidered as hexadectmal integer. They may, also include-alphabets A through F or athrough . The letter A-through F represent the, aumbers tO through 15. Following are the examples of valid hex integers:, , —— OX. Ox9F _OXhed__Ox, , \Ve rarely use octal and hexadecimal numbers in programming., , The largest integer-value-that can he stored is machine-dependent. It is 32767 on 16-bit, machines and 2,147,483,647 on it machines. It is also possible to Store larger integer, , Constants, Variables, and Data Types, , , , , with, cae, , , , , , , , constants on’ these machines’by appending qualifiers such as |. to the constants, Examples . 56789U or 56789u (unsigned integer), 987612347UL or 98761234u) (unsigned long integer}, 543 or 98765431 (long integer), The concept o and ntegers are discussed in detail in Section 2.7,, , Example 2 || Representation of integer constants on a 16-bit computel,, , The program in Fig.2.3 illustrates the use of integer constants on a 16-bit machine. The, output in Fig, 2.3 shows that the integer values larger than 32767 are nat. properly stored on, « 16-tut machine. However, when they are qualified as long integer (by appending 1.), tho, values are currectly stored. :, , , , Program, main{) |, printf("Ioteger values\n\n"); ., printf (Sid 4d %d\n"; 32767,32767+1, 32767+10); i, é printf("\n"); a i, ; printf("Long integer values\n\n"); t, { ; printf(*sld 41d Sid\n", 32767L,32767L+IL, 32767L+#10L); i, | Output |, , Integer values, , | 32767 -32768 -32759, , | * Long integer values *, eseceaeauoyier 32767 32768 32777, , Fig. 2.3 Representation of integer corey gp 16-bit machine, ye, | yA TS,, , Real Constants care (eeeeh, 3 \ts % ‘, , Integer n | i i, ger numbers are inadéquate to Fepresent quantities that vary continuously, such as _, , distances, heipt 5, , mE CSS, Heights, temperatures Prices, and, , numbers ¢ acer Pees . TES, ani $o0_on. S aes, , able ce containing fractional parts like 17.548, ees oh, eee, foul’ Constants. Further examples of real constants are: ae = “], , , , ae ke