C Basics C BASICS C CHARACTER SET Letters
C++ Basics
C++ BASICS C++ CHARACTER SET Letters A - Z, a – z Digits 0 -9 Special Symbols Space + - * / ^ ( ) [ ] { } = ≠ < >. ‘ “ $ , ; : % ! & ? _ # <= >= @ White Spaces Blank space, Horizontal tab (→) carriage return (← ), Newline, Form feed Other characters C++ can process any of the 256
Tokens The smallest individual unit in a program • Key words • Identifiers • Literals • Punctuators • Operators
KEYWORDS Words that convey special meaning to the language compiler break case catch char class const continu e default delete else enum extern float for friend goto if inline integer new 0 perato r private protect ed public register return short struct switch templat e this throw try typedef union
IDENTIFIERS An arbitrarily long sequence of letters and digits. The first character must be a letter: the underscore ( _) counts as a letter. Upper and lower-case letters are different. All characters are significant
VALID / INVALID IDENTIFIERS Valid Invalid Myfile DATA-REC _CHK 29 CLCT DATE 9_7_77 BREAK MYFILE MY. FILE Z 2 TOZ 9
LITERALS Data items that never change their value during a program run. • integer– constants • character–constant • floating–constant • string–constant
INTEGER CONSTANTS An integer constant must have at least one digit and must not contain any decimal point. It may contain either + or sign. A number with no sign is assumed to be positive. Commas cannot appear in an integer constant
TYPES OF INTEGER CONSTANT • Decimal Integer Constants (base 10) Eg. 1234, 41, +97, - 12 • Octal Integer Constants (base 8) Eg. 034, 071 etc. , ( digits between 0 – 7 only) • Hexadecimal Integer Constants (base 16) Eg. OCX etc. ,
CHARACTER CONSTANT It must contain one character enclosed in single quotation marks Eg. ‘z’, ‘m’ etc. ,
ESCAPE SEQUENCE IN C++ Escape Sequence Nongraphic Character a Audible Bell (alert) b Backspace f Formfeed n Newline or linefeed r Carriage Return t Horizontal tab v Vertical Tab \ Backslash On Octal number (On represents the number in octal) Null
FLOATING CONSTANT OR REAL CONSTANTS In fraction form • Must have at least one digit before a decimal point and at least one digit after the decimal point. It may have either positive or negative sign preceding. By default with no sign it is positive. In Exponent form • It has two parts : a mantissa and an exponent. The mantissa must be either an integer or a proper real constant. The exponent must be an integer. The mantissa is followed by a letter E
Valid / Nonvalid Real constants • In fraction form Valid Invalid • In Exponent form Valid Invalid 2. 0 7 152 E 05 172. E 5 17. 5 7 1. 52 E 07 1. 7 E -13. 0 17250. 26. 2 0. 1523 E 08 0. 17 E 2. 3 -0. 00625 17, 230. 50 152. 0 E 08 . 25 E-7
STRING LITERALS • It is a sequence of characters surrounded by double quotes
Diagrammatic representation Literals Integer Constant Charact er Floating Constant Decimal Octal Hexa Decimal String Literal
PUNCTUATORS/ SEPERATORS • [ ] ( ) { } , : ; * … = #
OPERATORS • These are tokens that trigger some computation or action when applied to variables and other objects in an expression
Diagrammatic representation Token Keyword s Decima l Identifier s Literals Punctuat ors Operator s Integer Character Floating String Constant Literal Octal Hexa Decima
- Slides: 19