You are on page 1of 16


Module 1 High Level & Low Level Language

A programming language such as C, FORTRAN, or Pascal that enables a programmer to write programs those are more or less independent of a particular type of computer. uch languages are considered high!le"el because they are closer to human languages and further from machine languages. #n contrast, assembly languages are considered low!le"el because they are "ery close to machine languages. The main ad"antage of high!le"el languages o"er low!le"el languages is that they are easier to read, write, and maintain. $ltimately, programs written in a high!le"el language must be translated into machine language by a compiler or interpreter. The first high!le"el programming languages were designed in the %&'(s. Now there are do)ens of different languages, including Ada, Algol, *A #C, CO*O+, C, C,,, FORTRAN, +# P, Pascal, and Prolog. A machine language or an assembly language is -nown as +ow!le"el language, which are closer to the hardware than are high!le"el programming languages, which are closer to human languages. .achine languages are the only languages understood by computers. /hile easily understood by computers, machine languages are almost impossible for humans to use because they consist entirely of numbers. Programmers, therefore, use either a high! le"el programming language or an assembly language. An assembly language contains the same instructions as a machine language, but the instructions and "ariables ha"e names instead of being 0ust numbers. Programs written in high!le"el languages are translated into assembly language or machine language by a compiler. Assembly language programs are translated into machine language by a program called an assembler. Compile

Runtime Library

Source File

Object File


Executable Program

Compiler is a program that translates source code into ob0ect code. The compiler deri"es its name from the way it wor-s, loo-ing at the entire piece of source code and collecting and reorgani)ing the instructions. Thus, a compiler differs from an interpreter, which analy)es and e1ecutes each line of source code in succession, without loo-ing at the entire program. The ad"antage of interpreters is that they can e1ecute a program immediately. Compilers re2uire some time before an e1ecutable program emerges. 3owe"er, programs produced by compilers run much faster than the same programs e1ecuted by an interpreter.


This is sometimes called a nati"e!code compiler.editor and binder. This process can be time! consuming if the program is long. a compiler from a low le"el language to a high le"el one is also possible7 this is normally -nown as a decompiler if it is reconstructing a high le"el language which 5could ha"e6 generated the low le"el language. A set of ob0ect files.a program e"en if it contains only one module. For this reason. . on the other hand.because you can brea. Cross compilers are "ery useful when bringing up a new hardware platform for the first time 5bootstrapping6. Typical compilers output so!called ob0ects. separately. can immediately e1ecute high!le"el programs.4"ery high!le"el programming language 5e1cept strictly interpreti"e languages6 comes with a compiler. The interpreter.a large program into small. which need not ha"e all come from a single compiler pro"ided that the compilers used share a common output format. A lin-er is a program that combines ob0ect modules to form an e1ecutable program. may then be lin-ed together to create the final e1ecutable which can be run directly by a user. more manageable pieces.any programming languages allow you to write different pieces of code. The most common is to compile the program7 the other method is to pass the program through an interpreter. There are two ways to run programs written in a high!le"el language. which it then e1ecutes. the compiler is the language. #n addition to combining modules. or sometimes to an intermediate language that still needs further processing7 these are sometimes -nown as cascaders. A compiler may produce code intended to run on the same type of computer and operating system 58platform86 as the compiler itself runs on. 3owe"er. $sually the translation is from a source code 5generally a high le"el language6 to a target code 5generally a low le"el ob0ect code or machine language6 that may be directly e1ecuted by a computer or a "irtual machine. Lin!e +in-er also called lin. howe"er. that basically contain machine code augmented by information about the name and location of entry points and e1ternal calls 5to functions not contained in the ob0ect6. 4"entually. Compiled programs generally run faster than interpreted programs. Therefore. a compiler translates high!le"el instructions directly into machine language. though. The ad"antage of an interpreter. A 8source to source compiler8 is a type of compiler that ta-es a high le"el language as its input and outputs a high le"el language. This is the 0ob of the lin-er. you may need to lin. when a programmer wants to 2 . In"e p e"e #nterpreter is a program that e1ecutes instructions written in a high!le"el language. An interpreter translates high!le"el instructions into an intermediate form. #n effect. is that it does not need to go through the compilation stage during which machine instructions are generated. it might produce code designed to run on a different platform. Compilers also e1ist which translate from one high le"el language to another. because it defines which instructions are acceptable. called modules. This is -nown as a 8cross compiler8. Alternati"ely. a lin-er also replaces symbolic addresses with real addresses. This simplifies the programming tas. you need to put all the modules together. interpreters are sometimes used during the de"elopment of a program. #n contrast.

as long as they are place within the 3 . #n addition. 4"ery Post cript printer. as in the case of main56. *A #C and +# P are especially designed to be e1ecuted by an interpreter. but runs on another. C code is portable. for e1ample. or programming ?6 tore the program @6 Run the program and get the result. A##em$le An assembler is a computer program for translating assembly language 9 essentially. Comments may appear anywhere within a program. assemblers pro"ide the ability to use symbolic names for memory locations 5sa"ing tedious calculations and manually updating addresses when a program is slightly modified6. structured programming language. a mnemonic representation of machine language 9 into ob0ect code. *oth interpreters and compilers are a"ailable for most high!le"el languages. is coded almost entirely in C. which was also de"eloped at *ell +aboratories. C &undamen"al# C is a general purpose.: !Coding. A function name is always followed by a pair of parenthesis. <6 Analy)e the problem and find out what are the input data pro"ided =6 . . Portability means that it is easy to adapt software written for one type of computer operating system to another type. The statements within a function are always enclosed within a pair of CD.out the result >6 . modify the logic or program depending up on the situation. A6 #f e1pected result is not getting. -eywords. and macro facilities for performing te1tual substitution 9 typically used to encode common short se2uences of instructions to run inline instead of in a subroutine. The program e1ecution begins in main56 function. The braces may contain combinations of elementary statements5called e1pression statements6 and other compound statements. it is strongly associated with $ni1. use an interpreter. These steps are collecti"ely -nown as computer programming.add small sections at a time and test them 2uic-ly. This operating system. ince it was de"eloped along with the $ni1 Operating system. #t is because it combines the best elements of high le"el languages with the control and fle1ibility of assembly language. %"ep# in Compu"e P og amming Computer programming is the art and s-ill of creating a computer program. '6 Translate the logic set in to program steps using the character set. allowed "ariable names and grammatical rules of the programming language. Creating a computer program in"ol"es: %6 $nderstand the problem thoroughly. and engineering. 4ach e1pression statement must end with a semicolon576.ennis Ritchie at *ell +aboratories in the %&@(Bs.e"elop logic to wor. science. and the format in which it is re2uired. C is often called a middle le"el computer language. As well as translating assembly instruction mnemonics into ob0ect codes.raw flow chart and write algorithms steps to formulate the logic. a defined set of instructions in source code that a computer can e1ecute. %" u'"u e o( a C P og am 4"ery C program consists of one or more functions. mathematics. #n addition. page description languages.ecide the actual outputs re2uired. such as Post cript. 3owe"er. Creating programs has elements of art. A cross assembler produces code for one processor. has a built!in interpreter that e1ecutes Post cript instructions. one of which must be main)*. interpreters are often used in education because they allow students to program interacti"ely. C was de"eloped and first implemented by .

7 8 .delimiters EF and FE.ata Types a"ailable in are Fa"a TEpe int float double char Fe#' ip"ion integer 2uantity floating point number double precision number single character TEpi'al Memo E ReGui emen"# < bytes or one word % word5> bytes6 < words5A bytes6 % byte 4 . digits or underscore. Comments do not affect the e1ecution speed and the si)e of a program. The definition of a "ariable will assign storage for the "ariable and define the type of data that will be held in the location. 9 / : 0 . auto breacase char const continue default do double else enum e1tern float for goto if int long register return short signed si)eof static struct switch typedef union unsigned "oid "olatile while All -eywords must be written in lower case. the names of the "ariables.These are used in a program to enhance its readability and understanding. *oth upper case and lower case letters are permitted. the digits ( to & and certain characters as building bloc-s to form basic program elements. *asic . Consider a simple program in c main56 C printf5G3ello tudentsH67EF print statementFE D the output will be G3ello tudentsH. The special characters are shown below + 6 . & < 1 = ) > * ? 2 @ 3 A 4 B 5 C Iden"i(ie # and DeE wo d# #dentifiers : #n C. ome e1amples of identifiers are Abc ta1Krate Ktemperature LM Place TA*+4 Ley words : C -eeps a small set of -eywords for its own use. Cha a'"e #e" o( C Language C uses the upper case letters A to I. These -eywords cannot be used as identifiers in the program. #t is possible to use upper case -eyword as an identifier. functions and arrays and "arious other user J defined items are called identifiers. Fa"a TEpe# C has a concept of Ndata typesN which are used to define a "ariable before its use. The first character of an identifier must be a letter or an underscore and subse2uent characters must be either letter. ince upper case and lower case characters are not e2ui"alent. 3ere is the list of -eywords used in tandard C7 you will notice that none of them use upper!case letters. the lower case letter a to ).

but it will ne"er be less than an ordinary int. long int or unsigned int. Recent C. as an ordinary int. imilarly.. The following e1ample defines the #ho " in" "ariable flag: short int flag7 The following e1ample defines the un#igned long in" "ariable ss_number as ha"ing the initial "alue 438888834: 5 . %. 4g: C char +etter7 +etter O N1N7 D . <. /hen the accuracy pro"ided by a float number is not sufficient. #t uses ?> bits gi"ing a precision of %> digits. The un#igned prefi1 indicates that the ob0ect is a nonnegati"e integer. int ! data type : int is used to define integer numbers. #nteger 2uantities can be defined as short int.Please note that there is not a boolean data type. with ? digits of precision. a long int may re2uire the same amount or more amount of memory. 4ach char type has an e2ui"alent integer interpretation. so it is a special -ind of short integer. 4g: C int Count7 Count O '7 D float ! data type : float is used to define floating point numbers. *ecause a signed type reser"es a sign bit.ata Type . 4g: C float . float Q double6 abo"e ha"e the following modifiers. The char type will generally re2uire only % byte of internal storage. 4ach unsigned type pro"ides the same si)e storage as its signed e2ui"alent. compilers do ha"e a boolean datatype. Floating point numbers are stored in =< bits. 4g: C double Atoms7 Atoms O <'(((((7 D char ! data type : char defines characters. short long signed unsigned The modifiers define the amount of storage allocated to the "ariable. These are -nown as double precision numbers. An unsigned has the same memory re2uirements. #ntegers are whole numbers with a range of "alues supported by a particular machine. in" reser"es the same storage as un#igned in". The si)e of integer "alue is limited to the range !=<@?A to =<@?@.iles O '. $nsigned integer si)e "aries from ( to ?''='.odifiers : The three data types5int. #t reser"es twice the storage for the number. A signed integer uses one bit for sign and %' bits for the magnitude of the number. the type double can be used to define the number a double data type number. An unsigned int can be appro1imately twice as large as an ordinary int. hort int may re2uire less memory than an ordinary int in word length.iles7 . >. =.?7 D double ! data type : double is used to define *#P floating point numbers. an unsigned type can hold a larger positi"e integer than the e2ui"alent signed type. For e1ample.

and not use it in a cashed way. .unsigned long ssKnumber O >=AAAAA=>7 . /hile unsigned chars ha"e "alues between ( and <''. of J sign. 6 . #t refers to a se2uence of digits. =. the program should always chec. Constants Constants Character Constants Integer Constants Real Constants Single Char Constants String Constants #nteger and real5floating point6 constant represent numbers. The "alue of constant cannot e1ceed minimum and ma1imum bounds. The following rules apply to all numeric constants. This means that if you reference the "ariable. The modifiers long float and long double can also be used e1plicitly. They are often referred to collecti"ely as numeric J type constants. #f an e1ponent is present. <.P. A real number may also be e1pressed in e1ponential form. %.ata type modifiers. For e1ample. for data that is to be passed to an #EO port. A decimal integer constant consists of set of digits preceded by an optional . signed chars ha"e "alues from J%<A to %<@.%>%'&7 pi cannot be changed at a later time within the program. const <. A "olatile "ariable is for dynamic use. signed or unsigned may be e1plicitly applied to char. it is assumed to the positioned to the right of the digit. #f a decimal point is not included within the number. Solatile : The "olatile -eyword acts as a data type 2ualifier. Solatile means the storage is li-ely to change at anytime and be changed but something outside the control of the user program.ata Type Rualifiers : %. "olatile const : The const 2ualifier is used to tell C that the "ariable "alue cannot change after initiali)ation. its effect is to shift the location of the decimal point to the right if the e1ponent is positi"e. the "alue <=@. or to the left if the e1ponent is negati"e. #nteger Constants : An integer constant is an integer "alued number. 4< means multiply by %( <. 4. Floating point Constants : A floating point constant is a number that contains either a decimal part or fraction. The constant can be preceded by a minus5 ! 6 sign if desired.the physical address 5ie a mapped input fifo6. Commas and blan. Con#"an"# Constants in C refer to fi1ed "alues that do not change during the e1ecution of a program. 4g: const float piO=. C has four basic types of constants. The "olatile statement pre"ents the compiler optimi)ation.&' may be written as <=@&'4< in e1ponential notation.spaces cannot be included within the constant.

The string of character used in a string constant is always stored in an ad0acent memory location. TcB. TFB. The first character in the "ariable name must be an alphabet. . formal parameters and global "ariables respecti"ely. fahrKtemp. alphabets and underscores. A character constant 5eg.of code. special characters and blan.slash character constants that are used in output functions li-e printf. These positions are correspond to local "ariables. count7 float ta1Krate. it is also possible to perform arithmetic operations on character constants. Further a single character string constant does not ha"e an e2ui"alent integer "alue while a character has an integer "alue. These combinations are called escape se2uences. G'. 3ere are some declarations int 41amples are GhelloH. Rules for constructing "ariable names : a6 b6 c6 d6 A "ariable name is any combination of ( to & digits.ata type must be a "alid data type and "ariable list may consist of one or more identifier names separated by commas. ince each character constant represents an integer "alue. Vn Vb Vt V( V" Vr Vf Va VV VW VN V8 V((( V1hh ! ! ! ! ! ! ! ! ! ! ! ! ! ! stands for new line bac. in the definition of function parameters. No special symbol other than an underscore can be used in a "ariable name. This character acts as a string terminator. but most are found at the start of each function. 7 . C supports some bac.HUH6. 41ample of character constants are T=B. All "ariables must be declared before they can be used. G&>'H. a single digit or a single special symbol enclosed within a pair of single 2uotes.cosine7 Sariable can be declared in three places. tring Constants : A collection of characters enclosed within a pair of double 2uotes is treated as string constant.=H.Character Constants : A character constant is a single alphabet. a"e7 double sine. Sariables can be declared at the start of any bloc. 5eg. Ha ia$le# Sariable is an identifier that is used to represent some specified type of information within a designated portion of the program. Gwell doneH. 4ach string constant always ends with a special character TV(B. although they consists two characters. and outside of all functions. numbers. inside functions. The general form of a declaration is Data – type variable – hori)ontal tab null Sertical Tab Carriage Return Form feed Audible Alert 5bell6 *ac-slash Ruestion maringle 2uote .ouble 2uote Oct Number 3e1 number 4ach one of these represents one character. #t is named location in memory that is used to hold a "alue that can be modified by the program. No commas or blan-s all allowed within a "ariable name. The character may be letters. T1B6 is not e2ui"alent to the string constant.

Type Conversion in expressions : /hen constants and "ariables of different types are used in an e1pression. >. A. All "ariables used in the e1pression must ha"e assigned "alues before e"aluation attempted. Arithmetic Operator +ogical Operator #ncrement and . ome of the e1amples of C e1pression are aFb. the conditions true and false are represented by the integer "alues % and ( respecti"ely. PreprocessorN is a translation phase that is applied to your source code before the compiler proper gets its hands on it.epending on the function performed.. #ts synta1 is as shown below Ydefine ANP+4K.ecrement Operator *it wise Operator . After that 5for the rest of the current source file6. ha"ing as its value the gi"en replacement te1t. which fall in se"eral different categories. <. C distinguishes between lowercase and uppercase letters in "ariable names. @. Ope a"o # C is "ery rich in built J in J operators. #t is a preprocessor directi"e.i"ision Operator Conditional Relational Assignment 8 . Penerally. The compiler con"erts all operands up to the type of the largest operand. which replaces instances of one piece of te1t with another.EIp e##ion# An e1pression is a combination of "ariables. #n C. All char and short int "alues are automatically ele"ated to int. A preprocessor line shown below defines symbolic constant Ydefine name text defines a macro with the gi"en name. constants and operators arranged as per the synta1 of the language.acro is a type of preprocessor.c 1Oy 1XOy . #t places more significance on operators than do most other computer languages. C includes a large number of operators. where"er the preprocessor sees that name.odulo . 41pressions can also represent logical conditions that are either true or false. . ?.1 4"aluation of e1pression : 41pressions are e"aluated using an assignment statement of the form: "ariable O e1pression7 Sariable is any "alid C "ariable name. %Em$oli' Con#"an"# ymbolic constants are constants of any type declared by using the Ydefine compiler directi"e. it will replace it with the replacement te1t. This process is called integral promotion. .#N ( Ydefine ANP+4K. the operator can be classified as %.AU =?( would define ANGLE_MIN and ANGLE_MAX to the "alues ( and =?(. which is called type promotion. respecti"ely. =. '. the preprocessor performs te1tual substitutions on your source code. #t is customary to use capital letters in defining symbolic constants. they are all con"erted to same type.

This operator yields the remainder of an integer di"ision.odulo . Thus the e1pression a. mean the same thing when they are used alone in statements.. binary or ternary depending on whether they operate on one.Thus the operands can be integer 2uantities. +ogical Operators : +ogical operators deals with the ways the relationships can be connected. operators can also be designated as unary. une2ual or whether one is greater than other. ?[>. )ero if the relation is false. . the "alue of U and Z would be %(%. They are Ope a"o . They are used to compare two operands to see whether they are e2ual to each other. The "alue of the relational e1pression is either one or )ero. a postfi1 operator first assigns the "alue to the "ariable on left and then increments the operand. Note that ?[> yields < whereas >[? >.ultiplication .a and a. #f we rewrite it as.i"ision The operands acted up on by arithmetic operators must represent numeric "alues. is "alid where as '. #t is one if the specified relation is true. the result is one. F E Pu po#e Addition ubtraction . These are unary operators since they operate on only one operand.. Consider the e1pression ?E>. modulo di"ision operator is used. C has the following three logical operators Ope a"o QQ ]] Pu po#e logical and logical or 9 .. then the "alue of 1O%(% and yO%((. #ncrement and .. not a constant..i"ision Operator : C pro"ides one more arithmetic operator [ called modulo di"ision operator. Arithmetic Operators : There are fi"e arithmetic operators in C.17 #n this case. To find the remainder. Relational Operator : Relational operators refers to the relationships that "alues can ha"e with one another. floating point 2uantities or character. Ope a"o X \ XO \O OO MO Pu po#e +ess than Preater than +ess than e2ual to Preater than e2ual to 42ual to Not 42ual to Relational e1pression are used in decision statements such as if and while to decide the course of action of a running program.. This operator wor-s only with ints and chars and not on floats or doubles. is not. and J called increment and decrement operators respecti"ely.#n addition to this classification. The di"ision operator5E6 re2uires the second operand be non )ero. The following figure shows these operators along with their meanings. The operator . The data items that operators act upon are called operands.. . The operand has to be "ariable.ecrement Operators : C offers two special operators .. adds % to the operand while J subtracts %. though the operand needs the integers. On the other hand. Consider the following 1O%((7 yO. 1O%(( and yO1. /e cannot use it on floating point numbers. two or three operators respecti"ely. *ut they beha"e differently when they are used in e1pressions on the right hand side of an assignment statement.. A prefi1 operator first adds % to the operand and then the result is assigned to the "ariable on the left.

M logical not The logical operators QQ and ]] are used when we want to test more than one condition and ma-e decision An e1ample is 5pX26 QQ 5rOO'6 Truth table for the logical operators is shown here using % and (. They can be combined with another e1pression. Another shorthand notation is listed below %ho " hand i .. This general form is 41pression % W e1pression < : e1pression = This forms say if e1pression % is true then the "alue returned will be e1pression < other wise the "alue returned will be e1pression =. and !! to ensure that your programs stay readable. An e1pression that ma-es use of the conditional operator is called a conditional e1pression. The conditional operators. Zou are recommended to restrict your use of . This e1pression can be written in place of traditional if statement. Assignment e1pression that ma-e use of this operator are written in the form #dentifier O e1pression7 /here identifier represents a "ariable and e1pression represents a constant. which allow abbre"iation of certain types of arithmetic assignment statements. I K a 1 $33= is e2ui"alent to I K a1$= $ K $31= Sersions where the operator occurs before the "ariable name change the "alue of the "ariable before e"aluating the e1pression.%(7 iOiF%(7 10 . a "ariable or an arithmetic e1pression. C has some operators. W and : are some times called ternary operators since they ta-e three operands. These operations are usually "ery efficient.O %(7 i FO %(7 EGuivalen" iOi. 41ample yO51X'W=:>67 This statement will store = in y if 1 is greater than '. Assignment Operators : The assignment operators are used to assign a "alue to the "ariable and is represented by e2ual to 5O6 sign. so I K LLi 1 )a3$*= is e2ui"alent to iKiL1= I K i 1 )a3$*= These can cause confusion if you try to do too many things on one command line. P J P&&J P44J +P ( % ( % ( ( % % ( ( ( % ( % % % % ( % ( Conditional Operator : imple conditional operator can be carried out with the conditional operators 5W And :6. other wise it will store > in y.

#n the following e1ample. the corresponding result bit is set to (. The operand must be of integral type. These operators are used for testing the bits or shifting from left to right. the bitwise!AN. I NI ( % ( ( #n the following e1ample. operator 5Q6 compares each bit of its first operand to the corresponding bit of its second operand.i !O %(7 i EO %(7 iOi!%(7 iOiE%(7 *itwise Operators : C has distinction of supporting special operators -nown as bit wise operators for manipulation of data at bit le"el. the corresponding result bit is set to %. sometimes called the 8bitwise complement8 or 8bitwise NOT8 operator. This operator performs usual arithmetic con"ersions7 the result has the type of the operand after con"ersion. *itwise operators may not be applied to float and double. nNum*O=. \\ : The bitwise shift operators shift their first operand left 5XX6 or right 5\\6 by the number of positions the second operand specifies. the right shift operator mo"es the data bits two positions to the right. EE 41ample of the bitwise!AN. ((((((%% nNumC O nNumA Q nNum*7 EE nNumC is now % and nNum*: 11 . Operator: Q : The bitwise!AN. operator int nNumAO%. Otherwise. thus changing the "alue of nNumA: EE 41ample of the bitwise right shift operator int nNumAOA7 EE beginning "alue is A nNumA \\ <7 EE ending "alue is < *itwise!AN. produces the bitwise oneNs complement of its operand. OneNs Complement Operator: ^ : The oneNs complement operator. operator 5Q6 compares the bits of two integers. #f both bits are %. nNumC7 EE (((((((%. I ( ( % % E ( % ( % I&E ( ( ( % nNumA #n the following e1ample. the new "alue assigned to y is the oneNs complement of the original unsigned short "alue: EE 41ample of the oneNs complement operator unsigned short y O (1AAAA7 EE "alue of y is (1AAAA y O ^y7 EE "alue of y is (1'''' *itwise +eft hift and Right hift Operators: XX. Mi"wi#e Ope a"o # 5unary6 bitwise complement *itwise TandB *itwise Te1clusi"e orB *itwise Tinclusi"e orB +eft hift Right hift +ogical Operators hift Operators ^ Q _ ] XX \\ +i-e other operators bitwise operators ha"e rules of precedence and associati"ity that determine how e1pressions in"ol"ed them are e"aluated.

the bitwise!e1clusi"e!OR operator 5_6 compares the bits of two integers. The natural order of e"aluation can be altered. ((((((%% nNumC O nNumA _ nNum*7 EE nNumC is now %(: ((((%(%( and nNum*: *itwise!#nclusi"e!OR Operator: ] : The bitwise!inclusi"e!OR operator 5]6 compares each bit of its first operand to the corresponding bit of its second operand. The first group has a higher precedence than the second. ((((((%% nNumC O nNumA ] nNum*7 EE nNumC is now %%: ((((%(%% OperatorPrecedence and nNum*: The operators within C are grouped hierarchically according to their precedence 5i. order of e"aluation6. Otherwise. nNumC7 EE ((((%((%. di"ision and remainder operations will be carried out before addition and subtraction. Operations with a higher precedence are carried out before operations ha"ing a lower precedence. the bitwise!inclusi"e!OR operator 5]6 compares the bits of two integers. nNum*O=. This is -nown as associati"ity. through the use of parentheses. #f one bit is ( and the other bit is %. nNum*O=. Another important consideration is the order in which consecuti"e operations within the same precedence group are carried out.(type) * & s right to left izeof * / % + << >> < <= > >= == != & left to right left to right left to right left to right left to right left to right 12 . nNumC7 EE ((((%((%. Thus multiplication. C OperatorPrecedence Operator(s) ( ) [ ] -> . Among the arithmetic operators. the corresponding result bit is set to (.. Associativity left to right ! ~ ++ -. F. the corresponding result bit is set to %. EE 41ample of the bitwise!e1clusi"e!OR operator int nNumAO&. #f either bit is %. I ( ( % % O ( % ( % I0E ( % % ( nNumA #n the following e1ample.*itwise!41clusi"e!OR Operator: _ : The bitwise!e1clusi"e!OR operator 5_6 compares each bit of its first operand to the corresponding bit of its second operand.e. EE 41ample of the bitwise!inclusi"e!OR operator int nNumAO&. and J fall into another. Otherwise. and .E and [ fall into one precedence group. the corresponding result bit is set to (. howe"er.. I ( ( % % O ( % ( % I4E ( % % % nNumA #n the following e1ample. the corresponding result bit is set to %.

The arguments must be enclosed in paranthesis and seperated by commas. followed by a list of arguments that represent information being passed to the function. C language does not ha"e any -eywords that perform iEo. ome functions return a data item to their access point7 others indicate whether a condition is true or false. though all implementations of the language include them. The general form of getchar56 function is character "ariable O getchar567 where charcter "ariable refers to already declared character "ariable. These library functions are not part of the language. which contain these library functions. $nformatted functions Formatted functions deal with the scanf56 and printf56 functions. A library function is accessed simply by writing the function name. "ariable names or comple1 e1pressions.e.^ | && || ?: = += -= etc left to right left to right left to right left to right right to left right to left left to right Li$ a E &un'"ion# The C language is accompanied by a number of library functions. getchar56 waits for a -ey press to accept an input. 41ample 13 .h\ #EO functions are classified into two types %. o this is called line buffered input. The general form of putchar function is putchar5character "ariable67 /here character "ariable refers to an already declared character "ariable. $nformatted function deals with getchar56 and putchar56 function which reads and writes a single character respecti"ely. 4ach program that uses a standard inputEoutput function must contain this statement Y include Xstdio. The arguments can be constants. This waits until a -ey press and then return its "alue. one character at a time.h\. Formatted functions <. getchar56 accepts the character that you typed on the screen For e1ample char func7 func O getchar567 putchar56 function : putchar56 function puts a single character on the screen. getchar() function : getchar56 reads a single character from the -eyboard. tandard #EO functions : These functions deals with character i. The header file for in"o-ing the iEo functions is Xstdio. C has standardi)ed header files. which accepts data from the input de"ice and writes it on a standard output de"ice. but they ha"e library functions that includes inputEoutput functions.

Qarg%. The third statement putchar5c6 will send the "alue of c. TyB to the screen. The output will be printed out in a specified format. The "alues of the "ariables will be stored in the addresses.a67 14 . Qc67 The "ariables defined in the scanf56 function are preceded by an ampersand5Q6 sign. scanf56 function : The scanf56 function reads the input data from the standard input de"ice especially from -eyboard. Formatted #EO functions : Formatted iEo functions deals with reading and writing data in a particular format. The function can accept any combination of numerical "alues. arg%.char c7 cOByB7 putchar5c67 c is a "ariable of character data type. strings and single character.c7 printf5G um of the numbers [d and [d is O [dH. scanf5G[d[f[cH.`. The general form of printf56 function is printf5Gformat specifiersH. ``.c.eaning [cRead a single character Read a decimal integer Read a floating point number Read a floating point number Read a floating point number Read a decimal. Qf. The input format begin with T[B sign tells scanf56 what type of type of data to be read ne1t. cO'7 aOb. #t is because we are sending addresses of "ariables to the function.Qarg<`. T[fB reads a floating point "ariable. he1a decimal or octal integer Read an octal integer Read a string Read a pointer Read a he1adecimal integer Read a +ong integer Read a double floating point number printf() function : The printf56 function writes the data onto a standard output de"ice.b.arg n67 For e1ample. For e1ample T[dB reads an integer "ariable.e. The general form of scanf56 function is scanf5Gformat stringH..Qargn67 For e1ample int a7 flaot f7 char c7 ``. C assigns the "alue TyB in the second statement.Qa. arg<. int a7 int bO%(. i. Con"ersion Character [c [d [e [f [g [i [o [s [p [1 [ld [lf .

isplay an octal integer .isplay a decimal integer . #t is terminated when an enter -ey is pressed.ouble 2uote Oct Number 3e1 number 4ach one of these represents one character.isplay a long integer Read a double floating point number 4scape se2uences used in printf56 function : C support some bac. The puts56 function returns a non negati"e "alue if successful.isplay a single character . The puts56 function writes the string to the standard output de"ice. These character combinations are called escape se2uences. Vn Vb Vt V( V" Vr Vf Va VV VW VN V8 V((( V1hh ! ! ! ! ! ! ! ! ! ! ! ! ! ! stands for new line bac.isplay a string . main56 C char stra=(b7 puts5G4nter tringH67 15 . gets56 and puts56 Functions : The gets56 and puts56 function reads and writes a stream of data represented as a string 5e. *oth the functions accept only a single argument.g.isplay a pointer . a character array6.isplay an unsigned integer .isplay a he1adecimal integer . although they consists of two characters. The gets56 function reads string from the -eyboard until a new line character is recei"ed.isplay a floating point number with e1ponent .slash character constants that are used in output functions. by e"aluating the sum in the abo"e hori)ontal tab null Sertical Tab Carriage Return Form feed Audible Alert 5bell6 *ac-slash Ruestion maringle 2uote . The string may include white space characters.isplay a signed decimal integer . Conve #ion Cha a'"e [c [d [e [f [i [o [s [p [1 [u [ld [lf Meaning . Consider an e1ample. puts56 can output only one string at a time.isplay a floating point number without e1ponent . The con"ersion character of the format string is almost similar to scanf56 statement.The output will be um of the numbers %( and ' is O %' printf56 statement returns the "alue of the specified "ariable.

@.orning In"e a'"ive P og amming .. printf5GVnName : [sH.name67 printf5GVnAge : [dH. such dialogs can be created by alternate use of the scanf56 and printf56 functions. /rite a program to find area of circle. feet. /rite a program to find area of rectangle. rate.#n inter2acti"e programming the printf56 function is used both when entering data5to create the computerBs 2uestions6 and when displaying results. scaf56 is used only for actual data entry. inch and centimetre. /rite a program to con"ert lower case alphabet to upper case using A C## "alues. /rite a program to find sum and a"erage of ' numbers. or "ice "ersa. where the computer as-s the 2uestions and the user pro"ides the answers.. <. The computer and the user thus appear to be carrying on some limited form of con"ersation. #nputs are basic salary. '. a scanf56 function. %(.A.. /rite a program to find area and "olume of a sphere. These dialogs usually in"ol"e some form of 2uestion J answer interaction. The first is a printf56 statement. causes the data item to be entered from the standard input de"ice. /rite a program to con"ert a gi"en number of days to months and days. The second statement. 16 .any modern computer programs are designed to create an interacti"e dialog between the computer and the person using the program. =..gets5str67 puts5G tring 4ntered isH67 puts5str67 D The output obtained is 4nter string Pood . which generates a re2uest for them.On the other hand.e.. `. For 41ample: printf5GVn4nter Zour Name :H67 scanf5G[sH. >. name and age are displayed. and . 3. /rite a program to con"ert the temperature in Fahrenheit scale to Celsius /rite a interacti"e program to find simple interest. &.Qage67 `.R.orning5#nput string through the -eyboard6 tring 4ntered is Pood . EIe 'i#e# %. /rite an interacti"e program to find salary of an employee. A. ?. #n C.A. The input data i. as a result of the group of printf56 statements at the end of the program.age67 Notice that two statements are associated with each input data item. /rite a program to con"ert Lilometer into meter.Qname67 printf5GVn4nter Zour Age :H67 scanf5G[dH.