When you want to succeed as bad as you want to breathe, then you’ll be successful.
--Your friends at LectureNotes

Note for Programming in C - C By KISHORE KUMAR REDDY

  • Programming in C - C
  • Note
  • Computer Science Engineering
  • 7 Topics
  • 109 Offline Downloads
  • Uploaded 1 year ago
Kishore Kumar Reddy
Kishore Kumar Reddy
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-2

Programming in C BASIC ELIMENTS In C , the basic elements include the set of characters, keywords, identifiers, data types, constants, variables, declarations, expressions, statements and symbolic constants. THE BASIC ELEMENTS OF „C‟ Name of the Element 1 Character set Keywords Contents/Characteristics Name of the Element Contents / Characteristics 2 3 4 Words, expressions and statements can be formed by the combination of alphabets, digits and symbols  Alphabets    Digits Special symbols Blank spaces In C, 32 Keywords are available. They are also called ‗Reserved Words‘ because each word is reserved for a predefined purpose.  Upper Case A,B,C…Z(26), Lower Case a,b…z(26)  0,1,2,3,4,5,6,7,8,9  # , * ,-, +, \, /, ;, :, ?, ! etc.  Non-printing characters. Auto, double, if, static,  Break else, int, struct, Case, enum long, switch, Char, extern typedef, union, Const, float register, void, Continue return, unsigned, while, Default for, short, do, Goto, signed  sizeof, volatile Each key word has a standard and pre-defined meaning and a pre-defined purpose as well. The meaning or purpose of keywords cannot be changed by a user. CONSTANTS C constants can be divided into two major categories as: 1. Primary constants and 2. Secondary constants ___________________________________________________________________________ Page 2 Prepared by J.Kishore Kumar Reddy & Dr A.Ravi Prasad

Text from page-3

Programming in C Primary constants can be divided into three types: a) Integer constants b) Real constants c) Character constants Secondary constants are divided into several types namely arrays, strings, structures etc. Classification of Constants CONSTANTS PRIMARY CONSTANTS Integer Real Constants Constant SECONDARY CONSTANTS Character Constant Arrays Strings Structures PRIMARY CONSTANTS Primary constants are mainly of three types. They are: a) Integer Constants  An integer constant is formed with an integer number.  Integer constants do not have decimal point.  The number may be positive or negative.  It includes zero also.  If no sign precedes the constant, it is taken as a positive constant. E.g:- 32768, -25, +25, 1000 , +32767 are valid integer constants. b) Real Constants  This is also called Floating point constants.  Real Constants must have decimal point.  Integer constants can‘t express a value in fraction or decimal form. Values of temperature, height, weight, prices etc., are normally in decimal form. In such cases, we should use real numbers.  These numbers have a decimal point and they are either positive or negative. ___________________________________________________________________________ Page 3 Prepared by J.Kishore Kumar Reddy & Dr A.Ravi Prasad

Text from page-4

Programming in C  If no sign precedes the number it is always positive.  No blank spaces, commas or special symbols (except (.) decimal point) are not allowed in real constants. E.g:- 0.25, -1.25, -0.251, +25.1  In no value is present either on the left-hand side or the right-hand side of the real number, the normal practice is to write zero/s. E.g:- 0.25, 5.0, 00.2, 0.20, -0.2, +7.0 (all these are valid real numbers) C) Character Constants  A character constant is a single character  It is either a single alphabet (lower or upper case), a single digit, a special symbol or a blank space enclosed within single quotes (‗) both pointing towards the left.  The length of the character constant must be one E.g: ‗X‘ ‗a‘ ‗5‘ ‗#‘ ‗ ‗ (The last one is the blank space charater) d) String constants  A string constant is sequence of characters enclosed within double quotes.  The characters include alphabets (lower case or upper case), digits, special characters and blank spaces.  This can also be defined as an array of (sequence of) character constants, whose last characters is \0 (null) character, which is automatically placed at the end of the string by the C compiler. E.g:- ―VERY GOOD‖, ― 2000 YEAR‖, ―$50K‖, ―A‖, ― ‖ (Null String) E)Blank slash Character Constants :  These are collectively called ‗ESCAPE SEQUENCES‘ because they are mainly used to create an escape from the present position.  The common features of all the escape sequences are they are formed with 2 characters. The first one is always the back slash (\) character and the second one is a lower case letter. E.g:- \n, \b, \t, \r, etc. ___________________________________________________________________________ Page 4 Prepared by J.Kishore Kumar Reddy & Dr A.Ravi Prasad

Text from page-5

Programming in C The following table shows a complete list of escape sequences for your ready reference. ESCAPE SEQENCE \n NAME New line \b Back space \t Horizontal tab \r Carriage return \a \f Alert Form feed \v Vertical tab PURPOSE Moves the cursor position to the first position of the next line Moves the cursor position to the previous position on the current line. Moves the cursor position to the next horizontal tab zone. Moves the cursor position to the, first position of the current line. Produces an audible alert Moves the cursor position to the first position of the next page. Moves the cursor position to the next vertical tab position. Explanation  \n (new line) this creates new line. When control encounters \n, it changes it position from the current position to the beginning of the next line.  \b (back space) this moves the cursor one position to back of its current position.  \t (tab) this moves the cursor to the next stop of tab. The screen of the monitor is generally divided vertically in to equal parts and each vertical part consists of 8 columns (means 8 character space) A tropical monitor screen at 80 characters width (width of 10 tab zones). When ever the cursor encounters at \t, it shifts to the beginning of next tab zone. The screen is generally divided into 10 tab zones as shown bellow.  \r this takes cursor a \t in the 4th zone as shown above it‘s position is immediately shifted to the 5th zone.  \a (Alt) its alts the cursor by making a sound. A speaker inside the computer is used to make such sounds.  \f (form feed) it‘s used to move to the computer stationary attached to the printer to the top of the next page.  \v (vertical tab) it creates a vertical tab that means the cursor moves down horizontally to next tab zone. ___________________________________________________________________________ Page 5 Prepared by J.Kishore Kumar Reddy & Dr A.Ravi Prasad

Lecture Notes