C nOTES

Share Embed Donate


Short Description

Download C nOTES...

Description

Steps for developing Programmer Algorithm Flow Chart Code into Light level Languages Input Preparation Compilation Corrections Test Process The first step in lives while developing a programme is Algonthm to represent the paper. The second step for developing a programme is called flow chatting. Flow chating means the digramaticaug representation of comp programe following are the symbols ureel in flow charts Start/End

,

I/O

,

Procuring

,

Precision

,

Looping

The next step for developing a computer programming to writing code into ligh level language. That mean writing a progrmme into a ligh level language, using prison Ted format for programme. It mean write instruction 8 Command which are regavd for that programme in ligh level language. Next step is preparing output. The next step is compilcation that mean to conveat the ligh level language into machine level language with the usr of compiler. Of there are errors it display that errors which are accused by you & the last steps is – Test proscenia exsiccation of programme. Note :- C Language is middle level language tecaure it has Characteristics of ligh level language & level language. Introduction to ‘C’ Programming */ C seem a strong name for programming language but this Strong sounding language is one of the most popular language to day ‘C’ was an offspring of a Basic combined programming language (BCPL) developed in lobos at Cambridge University it is also called as ‘B’ language this language is modified by Derma is Ratline at Bell laboratories in 1972 The new language was developed along with Unix operating System is strongly associated = Unix for many years ‘C’ was used mainly in aeaelemic environment But eventually with the relearse of ‘C’ compilers for Commericial use. Today ‘C’ is running under a no of operationg system inducing Ms Dos. Windowas. Importance of ‘C’ Programme written in ‘C’ are efficient & fast. This alue to its rariety of data types & powerful operations. It is many time faster than basic. There are only 32 keywords & its strength lies in its built in functions. Several Standred functions are available ‘C’ can be used for developing a programme ‘C’ to lightly portable to mean that ‘C’ Programming written for one computer can be run on another well -------------------- or no modification. Character set in C Programme * The Characters that can used to form words now & erpression depends upon the Computer on which the program is run. However a Subset of a charaete is available that can be used on most personal micro, mini & mainframe comp. The charaeten in ‘C’ programming are grouped into the fallowing catatonic. Letters, 2) Digits, 3) Special Chanauten, 4) White Spaces. Letters – Uppercase A to Z Lowarcase a to z Digit - 0 – 9 (decimal)

Special Characters. White Spaces – 1) Blank Space 2) Horizontal Tab 3) Camiage Teturn 4) New Line 5) Form Feed. Trigraph Characters Many non English keywords or Characters mentioned in the above table ‘C’ intendances the concept of paragraph sequences to provide a way to enter certain characters that are not available on some keyboard. Each trihgraph sequence consists of 3 Characters. (?? Followed by another characters. ) Eg. Trigraph seq. Tramlation ??= ??( ??) ??< ??> ??! ??/ ??’ ??-

# [ ] { } \ ^ ~

‘C’ Language is a middle Level Language because it has a characteristic of ligh level language & low level language ANSI – American national standred instars. * Special Characters , . ;

Comma Paved Semicolon ? : “ !

Apostrophe Quotation mark Exclamation Vertical bar F. slash B. slash Tilde Underscore Dollar sign.

/ \ ~ _ $ % # & ^ * __ + < > ( ) [ ] { } The keywords & identifiers in ‘C’ Every C word is classified as keyword or an identifier.

Hash Amper Sand Canet Asteric Minus Plus Les than Greater than Left parenthesis Right parenthesis Left bracket Right bracket Left brace Right brace

All keywords have fix meaning and this meaning cant be change keywords serve as basic bulling blocks for programme & statements. All the keywords must be written in bwercare. The keywords in ‘C’ are listed as below. 1) Auto 2) Break 3) Case 4) Char 5) Const 6) Continue 7) Default 8) Do 9) Double 10) Else 11) Erne 12) Extern 13) Flat 14) For 15) Go to 16) If 17) Int. 18) Long 19) Register 20) Return 21) Short 22) Signed 23) Size of 24) Static 25) Stat 26) Switch 27) Type def ? 28) Union 29) Using 30) Void 31) Volatile 32) White. Identifier Reefers to the name Of variables, function & arrays. There are user defined names consist of sequence of letter & digit with a letters as a first character both uppercase and lowercase letters are permitted although lower case letters are commonly. The under score character is also permitted in identifier. Constants Constants in C refers to fixed values that do not change during the execution of programme C supports several types of const. They are as Constant

Numeric Const

Integer Const

Character Const

Float Const

3 333333333333333 33 3

333333333 3333333

Integer Const An integer Const rafters to a seq. of digit there are 3 types of integer namely decimal octal hexadecimal intger const is a set of digit 0 – 9 preceded by an optional - or + sign valid eg – of decimal int const are 123 – 321, O + 78 Note :- Spaces, Commas & non digit Char are not permitted bet digits. Octal constant An octal int const consist of any combination of digit from the set of 0 – 7 with a leading ‘o’ zero eg – 0,3,2,7, 0, 0,4,5,3. * Hexadecimal Constant A seq. of digits preceded by 02 or ox is Consider as hexadecimal integer. They may also include alphabet A – F or a – f following are the eg. 0x2 0 x 1F 0 x bcd. we rarely use octal and hexadecimal nos in programming. A) Real Constant / float const. Integer numbers are inadequate to represent quantities that are very continuously, such as distances, lights, temp prize & so an. These quantities are represented by no. Containing fractional part like 17.548 such no ar called real or flouting point const further eg of real consts are 0.05, -0.75, 435.36, + 247.0. These nos are shown in decimal notation having a whole number followed by a decimal point & the fun part it is possible to omit digits

before the decimal point of digits after the decimal point i.e. 215 , ’95 , . - .71 +.5 are all the real numbers a real no may also be expressed in exponent ion or scientitic notation. Single Character Constant A single Character constant contains a single character enclosed within a pair of quote (‘ ’) eg – of character constants are ‘5’ / ‘a’ / ‘ ; ’ / ‘ ’ Note :- that the character const ‘5’ is not same as 5. the last const is a blank space. Character const have integer value known as ASCII value. C) String Constant A string constant is a set of characters enclosed within a double quote “ ” The character may be letters, numbers sepelial characters & blank space eg.- one “helo” / “1987” / “ well done “ / eeg “?……!” / “5+3” / “X” Remember that a character const ‘X’ is not equvalant to string const “X” further a single character string const doc not have an equralant integer value while. Character strings are often use to built meaning – ful programmes. D) Back slash constant ‘C’ supports some special ----Shash const that are used in output funn . The list of Back slash character const are as follows. ‘ \ a’ __ audioable alart / bell ‘ \ b’ __ Back space ‘\f’ __ Form feed ‘\r’ __ Carriage retain ‘ \ w’ __ Vertical tab ‘ \ n’ __ New line ‘\’ __ Single quote ‘\“’ __ Doable quote ‘\?’ __ Question marts ‘ \\ ’ __ Back slash ‘\0’ __ null Variables A available is a data name may be used to store a data values unlike const that remain changed during the execution of a programme a variable may take different. Values at different times during execution. A variable name can be choosen by the programmer in a mearingful way so as to refrect its funnor nature in the programme. Some eg. Of such name are – Average. Light Total Counter_1 Class_ Strength As mentaioned eariar verable name may consist letters, digit & the undersore characters, Sub. To the following condnThey must begging – a letters. Some sys. Permit underscore as the first character. ANSI recognizes a length of 31 Characters however the lengh should be eight character since only the first 8 characters are prated as significant by many compilers. The upper case & lower case are significant ie. the veiable Total, is not same as total or TOTAL. The variable name should not be a keyword. Blank space is not allowed. DATA TYPES

‘C’ language is rich in its data types. Srorage representation & machin instruction to handle constants differ from machine to machine. The vaiety of data types available allow the programmer to select the type appropriates to needs of the application as well as the machine. ‘C’ supports 4 classe of data type. Primary data types. User – defined data types. Derived data types. Empty data sete. Primary / fundamental data – types All ‘C’ Compiles support 4 fundamental data types. Namly integer (Int), character (Char), floating point (float), double precisisn floating point (floas), Many of them also offer extended data types such as long integer (Long - int), & Long – doable.

Primary data Types

Integer

Character

Signed type Int Short int Long int

unsigned type ----//--- int ---//---- int ---//---- int

Signed Charas unsigned Char.

Floating Point Types Float

Double

Long double

Size & Ranges of data types on a 16 bit machine Types Cnar or signed char Unsigned char Int or signed int Unsigned int Short int or sigred Unsigned short int Long int / sigred C. Iint 2,147,483,647 unsigrd L. Int double Long double

Size (bits) 8 8 16 8

Range - 128 to 127 - 0 to 225 - 32, 768 to 32, 767 0 to 65535

8 32

0 to 225 - 2,147,483,648, to

32 32 64 80

0 to 4, 294, 967,295 3.4E – 38 to 3.4Et 38 1.TE –308 to 1.TE + 308 3.4E –4932 to 1.1E +4932

Integer data types Integer are whole no E a range of values supported by a perticatar machine. Geneally integers occupy one word (16 – bit) of storage & since the word wize of machines vary (typically 16 or 32 bit). The size of an integer that can be stored depends on the computer. Generally we use 16 bit word length. The wize of the int. value is limited to the range – 32768 to + 32767 ie. (2 15 to +2). In order to provide some controle over the tange of the numbers 8 the storage space ‘C’ gas 3 clases of integer storage, namy short – Int. 8 long Int. in both signed & unsigned forms. Floating data types Floating points or real numbers are stored in 32 bits (on all 16 bits & 32 bits malhine), E 6 digits floating points fluffy points no one define in C by keyword float Glhen the acery provided by float is not sufficient the type double can be used to define the numbers. A double data type no uses 64 bits giving a floating point of 14 digits. To extend the floating point we may use long double wihich use 80 bit. Character type A single character can be define as character data type (char) type data. Character are unsaly stored in 8 bit of internal storage A qutifer signed 8 unsigned may be applied to char. Delcleration of Veravles After designing suitable veriable name you must delclear them to the compler, Dedlaration does now things It tells the compiles what is the name of veiable. Its specifies that , what type of date type veriable will hold. The declaration of veriales must be done before they are word in the programme Declaration of primary data types veriable A veriable can be used to store a value of any data type the syntax of declaing a veriable is as Eg.-

Data type v1, v2, v3 ………….. Vn; int total; Int total, menus, class; Float light; Double weight ; Long int a; Long double amount;

V1, v2, … Vn are the names of revibles are separated by comms (,) a declaration statements must end E ; Operator An operator is a symbol that tells the computer to performs mythical or logical operations. Operators are used in programme to manuculate data & verible. They usually form a part of mathemical or logical e xpression. C operator classifides in to noumbers of categories as follows arithamatics operator . relational operator. Logical operartor Assignment /shorthand operators Inrement and decrement operator Conditional operators Bit wise operator Special operators arithmetic operator ‘C’ provides all the basic arithmetic operator like +, -, x, :- , etc. these can operate on any built in data type allowed in ‘C’ the anargoperatior in effect multiplay its apearand by – 1 therfore a number preceded by – signed changes its signed. + add n or anary plus. substtraction , unary minus * multiplication / division % modulo division the modulo division producs the reminder of an intger division eg. Of aritmatic operator are a-b, a*b, a%b, -a/b, -a*b, a+b Relational operator We often compair two quantities & depending on their relation to take a qrfain decigion eg. – we may compair age of two person or the prise of two items & so on. These comparison can be done with the help of relationl operator & expressions such as --a 55 & & salary > 1000) If (number < 0 ) 888 I I number > 100)

Assignment operator /short hand operator These are used to assign the result of an expression of an expression to a variable. We have seen the usual assignment operator =. C has a set of short hand assignment operators of the form. Syntax -- V. OP = exp V – Variable, exp – expression & Op – operator - a c binary automatic c operator Op - is known as short hand assignment operator some of the community used short hand assignment operator are illustrated as follows. A=a+1 a+=1 A=a- 1 a- = 1 A = a * (n-1) a * = (n - 1) A = a /(n+1) a / = (n + 1) A=a%b a%=b The use nof short hand operator has 3 advantages. What appears on the C Left hand Side need not be repeated & therefore it becomes easier to write. The statement is more concise & easier to read. The statement is more efficient eg. Value (5*J-2) = value (5*J-2) + data. Using short hand operator value (5*J-2) + = data. Increment & decrement operator ‘C’ has 2 very useful operator not generally found in other languages these are increment & decrement operator i.e. + + & - - respectively. The operator + + add 1 to operand, while - - subtract 1 from operands. Both are unary operator & take the following form.

C type. H---This is another system file like < stdio .h >, This file contains the character funn. Like.

Is alnum (c) - is c alphanumeric char Is alpha (c) - is c alphabetic char Is digit (c) - is c a digit Is lower (c) - is c lower char Is upper (c) - is c upper char Is print (c) - is c print char Is punct (c) - is c a punctuation make Is space (c) - is c a blank space To upper (c) - conrert a lower to upper To lower (c) - convert a upper to lower. It you want to use there all funn add a line in links seetion of prog. Like

# include Putchar ( ) This function is used for single character output it is a output function. Syntax---Variable = putchar ( ) ; Switch statement ----‘C’ has a built in multiway decision statements known as a switch. The switch statements test the value of given variable (expression) against the cost of case values & when the match is found a block of statement associated with case is executed. The general form of switch statement is as follows ---. The expression is an integer expression or characters. Switch (expression) { Case value 1 : Black 1 ; Break ; Case value 2 ; Block 2 ; Break ; !!!! Default Default block ; } Statement x When a stwich is executed the value of expression is succe ssively compaired against values 0, value 1, value 2. If case is found whose matcher with the values of expression then that block of statement that fallows the case are executed. Break statement ----Bread Statement at the end each block signals the end of particular case & cause & exit from the switch statement. Transferring the control to the statement x. The default is optional case. When prenent it will be executed if the value of excretion demote E any case values. If not present no action takes place. If all matchs fails & the control goes to the statement x. GOTO Statement --‘C’ supports the goto statement to branch unconditionally from one point to another in the programme. Although it may not be essential to use the goto statement in lightly structured language C, these may be occacsion when the use of GOTO requiret alable inorder to ideritify the place where the branch is to be made. A lable is any valid veritable name (must be fallowed by colon(:) syntax --- goto table : label : statement While Statement --(Decision malting & looping ) --The simplest of all looping str. In ‘C’ is the while statement. The statement syntax of while statement Is. – While (test cont n) { Body of loop. } The while statement is an entry controlled loops statement. The test contn is true then the body of loop is executed. After excoriation of the body the test cond n is one again evaluated & if is true the body is executed on again. This prceres of repoated

exicution of the body cmtinuex unlit the test condn finaliy become false & the control is transferred all of continuser E the statement immediate after the body of loop. Eg. # include (stdio . h) Main ( ) { int I=0, sum=0 ; while (I < = do) { I = I +2 ; Slm = sum + I I } print f (“ % d ; sum); } The Do statement ---On some occasions it might be nevermore to loop before the test perfrm such situation can be handled E the help of do statement. The syntax of do statement is Do { body of loop } while (test condn); On eructing the do statement the prog. Procered to evaluate the body of loop first & end of the loop the test condn in the while statement is evaluated of the condn is true the prog. Continase to evaluate the body of loop once again. This procers continues as long as condn is true. When the condn becomes false the loop will be terminated 2 the control goes to the statement that appears immediately after the while enactment. For Loop ---For loop is another entry control loop that provider a more consiser loop control str. The general format of the ofr loop is – For (initialization; test- condn ; increment ) { Body of loop } The exsiccation of the ‘for’ statement is as fallows. initialization of the control versatile is done first, using assignment statement such as I=1, & count = , The variables is count are known as loop control variables. The value of the control variable is tested using the test condn the test condn is a relation expression such as I
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF