0% found this document useful (0 votes)
4 views6 pages

Programming - Chapter - 2 - Introduction - To C.

C is a general-purpose, structured programming language developed by Dennis Ritchie at AT&T's Bell Laboratories in 1972, bridging the gap between machine language and high-level languages. Its key features include concise programs, a rich set of built-in functions, portability, and suitability for both system and application programming. The document also discusses the rules for naming variables, types of constants, and the significance of identifiers in C programming.

Uploaded by

RJ Productions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Programming - Chapter - 2 - Introduction - To C.

C is a general-purpose, structured programming language developed by Dennis Ritchie at AT&T's Bell Laboratories in 1972, bridging the gap between machine language and high-level languages. Its key features include concise programs, a rich set of built-in functions, portability, and suitability for both system and application programming. The document also discusses the rules for naming variables, types of constants, and the significance of identifiers in C programming.

Uploaded by

RJ Productions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
CHAPTER = oe = A! INTRODUCTION = Cis a programming language developed at AT and T’s Bell Laboratories of USA in 1972. It was designed and written by Dennis Ritchie. C is a general purpose, structured programming language. Its instructions consist of terms that resemble algebraic expressions, supported by certain English keywords such as if, else, for, do and while, In this respect, C resembles other high-level structured programming languages such as Pascal and Fortran. C.also contains certain -additional features, that allows it to be used at a lower level. Thus, C is a middle level language which bridges the gap between machine language and the more conventional high-level languages. This flexibility allows C to be used for “system programsning” (e.g., for writing operating systems) as well as for “application programming” (eg., for writing a program to solve a specified system of complicated mathematical equations or to handle transactions at a shopping mall). [22 IMPORTANCEOFC | Se C is a popular programming language due to its various qualities. The main characteristics of C language are given below : 1. ‘The programs written in C language are very concise as it has a large number of operations included within th age. {2 Itprovides rich and large set of built;in functions, operators and data types that can be used to write any complex program. — ~~ 4, Cprograms are highly portable, as compared to other high-level languages. This means that C programs written on one computer can be run on an vith little or no alternation. 5. Itprovides only 32 keywords. 6. Clanguage is format free language. 7. It is well suited for developing both system software and application software as it combines the capabilities of an assembly language with features of a high level language. 1" re aut wailnble for co" ip! ams qu sump ares aoe ed prgraine aeNT aaa wet i plocks. A prope? kes acre sirutred inntenee esi 10, Callows userstowrite ' capabilities ofthis lank | Ba’Germne sranreowimne. adaitional brary fan ngcean be extended ot iy program debURRINK Lent now about numberSs a of all nites. anamer ent Bronk & probly oy those modules Maken a egy tt ey MH ong sans ofthe ot. THY8 he Foto ggg by the users. Sy charactors and special amg), | BL intmonuction toe [ S z oa 1B ‘Tho compiler ignores whito spaces untons they are part ofa string constant. £e, Cisa free orm Inngunge (it ixnores spacer). White rpaces may be used to separate words, However they ‘nro not ued In between the keywords and identifiers. Trigraph Charoctore Mony keyboards may not support all the characters that belong to the C-character set. ‘Therofore, C provides a viay for usors to enter characters not available on some keyboards by providing the concept of “trigeaph” sequences. Each trigraph sequence consists of three charactors which aro two question marka followed by another character as shown in table 2.2, i wemust mn ‘ion, Before progrumning 9 dan combined orm a nation ANSIC Trigraph Sequences Used in C and how these are constr _ $ C-Character Set secon character st, Characters aro used in programy ‘Trigraph sequence “Translated character Like any other language Css iSO paractr st in C consists of upper and Joye, 71 mene form identifies, numbers and expressions. ‘ond white spaces. The slphabots and digits gy, n- tilde case alphabets, digits, specie! ehsras8% The entire character sets given in table 1 phanumeric characters : Re number sign nm (eR bracket mm) J right bracket Re (eft brace Tpecial Characters > Jright brace “comme “apadrophe underscore . Table22 «period * quotation mark Sdollar sign cS, ar aa 7 vente | tru Srmentaes_ || ps _ EE colon ‘etacog ange brake vite | oftokens as shown in the following Bigure : | vertical bar (or greater than sign) * astorik | Islash (et pareathesis ) right parenthesis \backslash (eft bracket Iright bracket minus sign (eR brace J right brace + plus sign. White Space Characters Blank g 7 = ~ i Keone Horizontal tab Carriage return =w. Vertical tab Form feed Syataxofa language ‘Table2 that pre PROGRAMMING 1. > ~——t—t—t— ; ‘ & wy (2s. KeyworDS cali Keywords, that have saan Preeti There are certain reserved 0 ris sor weiintended os an they canna meaning in C. These keywords oa” | ‘used as programmer-defined identifiers. ‘The standard keywords are a signed unsigned | eto auto o sizeof void | break int static volatile | case else 7 an , 189 ruet ile $ register switch return typedef short union alia inclade some or all of the following keywords : | ‘Some compilers may huge near entry pescal Some Ccomplera may recognize other keywords. A reference manual should be consulted __ obtain a complete list of keywords for your particular compiler. ps. constants E ey There are four basic types of constantsin C. These are: co Constants Constants “opens Character constants | Inuger Real Single Character String ] | Constants — Constants ee a INTRODUCTION 11 Integer Constants ‘An integer constantis an integer-valued number. Thus, it refers toa sequence of digits. ‘The following rules apply to the integer constants: 5. The value of a constant cannot s. For each type of constant, these bounds will vary from one C compiler to another. For a 16 bit ‘computer, the allowable range for an integer constant is - 32768 to + 32767. Integer constants can be written in three different number systems: decimal (base 10), ‘octal (base 8) and hexadecimal (base 16). Decimal Integer Constant ‘A decimal integer constant can consist of any combination of digits taken from the set Oto 9. Ifthe constant contains two or more digits, the first digit must be something other than 0, like 123 82767 +78 OO. 188 - 321 Octal Integer Constant ‘An octal integer constant can consist of any combination of digits taken from the set 0 to7. However, the first digit must be 0, in order to i ‘examples of octal integers are 0 037 Hexadecimal Integer Constant A sequence of digits beginning with Or or OX is considered as a hexadecimal integer. It can then be followed by any combination of digits taken from the sets 0 to 9 and a to f{cither uppercase or lowercase). The letter a tof(or A to F) represent the decimal numbers 10 to 6. Some valid hexadecimal constants are a oxe ‘The magnitude ofan integer constant can range from zero to some maximum valve that varies from computer lo computer. A typical maximum value for most computers is 32,767 0a 16-bit machines1nd 2,147,483,647 on 32 bit machines. 0733, OXabed = OOF | PROGIAMIING W @ it stants ‘The following are same exarplesef invalid integer © @ 32,156 = — contains comma ; (i 921660 © — contains decimal pint (id 3208 = — cantainsanexponent (iv) = — should contain atleast ned ‘Real-Constants ‘Areal oQoting pein ia base 10 nuber that ents eter# dese Point or aq exponent or both. For example, sow 00s -075«—«N6G6TE+S © 121212 GE -2 ‘The following rules apply to all real constants: (a) Areal constant must have atleast one digit. ©) Temusthave a decimal point ©) Itcancither be positive or negative. @) Ifno sign precedesit, it is assumed to be positive. ‘The exponent form consists of two parts : mantissa and exponent, These can be used to Fepresent the values of constants that are cither too small or too big. For example, the real constant 1.6667E + Shas a mantissa value of 1.6567 and an exponent +8, In exponent form, the interpretation of Moating point number is same as scientific netation, Just that base 10 is replaced by letter E (ore). Thus the number 1,2 x 108 is equivalent to 1.2E ~Sor L2e-3, oat natant havea much greater range than integers, Typically, the magnitude ofa loating point constant ranges from3.4B ~ 38to maximum of 846 + 38 on 16 bit machines and LE-308 (0 1.7E + 308 on 32-bit machines. Also, the value 0.0 (less than 3.48 - 38 or pretreat faltreal constant eatig-yin constant are normally represented as double rein quanti However the sufixes for F may be used to force single precision and or louble precision further. The pretsion of real constants (ée., the number of INTRODUCTION 10 °¢° b (d) The rango of real constants expressed in exponential form is from 3-4e — 38 to ‘Sele 98 for 16-hit computers, Invalid Real Constanta ‘The following aro some examples of invalid real constants : () 20,125.0 — contains comma (i) 26325 — docs not contain decimal point (ii) 253013.2. — exponent should bean integer charactor Constants (M.D.U, 20131 ‘Accharactor constant isa singlealphabet,asingle digit or asingle special eymbol enclosed ‘within single quotation marks inverted commas). oo a jave integer values that are machine dependent. Thus, integer values. representing the character may be different on different machines. The constants themselves are independent of the character set. This feature eliminates the dependence of a program on. any particular character set (like ASCII or EBCDIC). 5 ‘String Constants: A stein yumber of consecutive characters (including whitespace characters) eri¢losed in double quotation marks, For example “green”, “Hello”, “$ 18,90", “WELL DONE”, "X". Sometimes special characters may also be included as a part of a string constant, These characters must be represented in terms oftheir escape sequences which are discussed in next article, At the end of every string constant, the C compiler automatically adds a null character (\O)s the last character ofthe string. This character is not visible when the string is displayed. However, by searching for the null character, end of every string can be identified easily Itis worth mentioning that a character constant like ‘A’ isnot equivalent to corresponding string constant “A. A character constant has an equivalent integer value whereas the string constant actually consists of two characters - the specified character ‘A’ followed by the null character (\0") and does not have an integer value. Escape Sequences (Backslash Character Constants) -C-supports some special backslash character constants thatare used in output functions. ‘These aro used to express cortain non-printing characters as well as the backslash (\) and the icU. 2013), “™ PROGRAMMING IN © Dell (alert) ‘backspace formfeod newline (line feed) carriage return horizontal tab vertical tab quotatioa mark © apostrophe (") question mark) backslash (\) Identifiers are used for naming program elements, ie., variables, constants, functions, arrays, etc. These are defined by the user. The identifiers should be given relevant and meaningful names so thatthe programs canbe easily understood INTRODUCTION 10°C (29. RULES FOR NAMING A VARIABLE a = ‘The various rules for naming a variables are as follows 1, Variable names must begin with a letter of the alphabet. In C, the underscore charneter(_)is considered a letter. However, a variable name beginning with underscore character should be discouraged to prevent possible conflict with some special system ‘names that begin with the underscore, - 2.The first character can be followed by any number of letters or digits from 0 through 9. ‘3, Blank space, period, semi-colon, comma or slash and all such special characters are not permitted in variable names. 4, The compiler regards uppercase and lowercase letters as different and they can be used in constructing variable names. Therefore, the variable names NER, neer and Neer are all regarded as three separate variables in C. The usual convention for naming variables in C is to declare them in lowercase. 5, Keywords cannot be used as variables names. Since keywords are generally in lower is possible to use a keyword in upper case as an identifier. However, it is sred as a poor programming practice. 6. On most computers, only the first seven or eight characters are used to identify a variable. No other variable used in the program should begin with the same seven oF eight characters. For example, the names variable 1 and variable 2 cannot be distinguished by sueh compilers. Some valid variable names are: company salary average total interest sun count future_val curr val When selecting variable names, the name should be chosen so as to describe the role that the variable is desired to play. For example, iftwo values are to be added and their result is to be stored in a variable, then the variable might be called sum. Naming it anything else would result in difficulty in understanding it later on. The purpose of such a naming convention in selecting a variable names that it gives all the possible infarmation to a reader ofthe program. Usually, the letter O ean be confused with the number 0 and lower letter I can be mistaken for Ba vannaes © Variable isa data-item whose value can chan particular instant of time it has a value say 9, itmay have another value say 15 at anyother instant of time. However, a variable storing integers must hold an integer at all times. When we declare a variable, we create a particular storage in the memo, i rage ‘The scope of avi fers to the portion of program in which it can be used. no obmaaereice ie during the execution of program, Ifata ‘The difference between variables and constant is that, in a variable the content of the memory location may change ic, value ofthe data item may ch, i constant the value remains fixed and cannotbe changed, 2” Never in the case of the number 1 and vice-versa. Such names as LOGO and GOAL are not much different from LOGO and GOAL respectively. It is better to avoid them in confusing situations. Invalid Variable Names ‘The following are some examples of invalid variable names { Saman — first character should be an alphabet ® paper3 — should noteontain space (iif) rate @ interest. — should not contain special symbol (iv) auto. should not be keyword. ' NN 1 2 a What are constants ? 4 6. 107 -~ we 13. Which charactors eomprise the Mey cs of C? of constants in C. 1 characteristi gui i pasie scribe the four (KU. 2016, 12, 09, 8; Mp My What are the gener®l Name and des “i tants. «tho rules that apply & all numerie type c7mS KU ay Summariz ; de of an integer Typically, wha! decimal, octal and hexa constant ? State your am ‘fb 1 is the largest permissible magnites decimal. Deseribe two different ways jn which floating point constants can be written. What specia} Fy apply in each case ? 3 2 What are Jong integer constants 2 How do these con, tton and identified ? stay er and floating point constants. Under yy What are unsigned integer constants ; differ from other integers ? How can they be wri curacy between intes Describe the differences in ac vreumstances should each type of constant be used ? What is an eseape sequence ? What is its Purpose 2 (M.D.U. 2015, 14; KU. 2015,n What is a string constant ? How does a string constant differ from @ character constant ? (M.D.U. 2016, Can eseape sequences be included in a string constant ? Explain. Which ofthe following are valid C constants. Recognize their type (a) 0.6 () 12345678 (©) 0515 (a) 018edf'xyz’ ) 9.3e12 pte @) 0.808 « (a) “180-12” 4 j @ _Ox87e3ha () “New York, NY 100” « ; ‘ ) 27,822 ( ‘8.15PM 1 (m) ‘at (ny NO (0) 0.86408 wav i (q) ‘1052 4 Define jiabl Cc Head 7 variable in C and also di s0 discuss rules for defining a variable in C. pf wap.u. 2015; 80"

You might also like