CPP NOTES
C++ (pronounced “ C plus plus”) is a language developed at AT & T Bell laboratories USA by Bjarne Stroustrup in the 1980s.
It is a powerful, popular, compiled, and object-oriented programming language [OOP]. It is the “successor” to C, a procedural language
(the “++” is called the successor or increment operator in C++)
It is an added (incremented) version of C language. (C with classes)
(the “++” is called the successor or increment operator in C++)
It is an added (incremented) version of C language. (C with classes)
Program is a sequence of instructions given to a computer to be executed to perform a desired task.
C++ CHARACTER SET
- It is a set of valid characters that a language can recognize.
- It represents any letter, digit or any other sign.
- It is the fundamental units of that language.
Letters: A-Z, a-z
Digits: 0-9
Special characters: ~ ! @ # $ % ^ & * ( ) _ - + / : , . ; ’ ” = < > ? { } [ ] \ |
White spaces : Non graphic characters (Back space, Horizontal tab, Carriage return , Newline,etc)
Other characters: any of 256 ASCII characters
TOKENS
The term `token’ in C++ language is similar to the term ‘word’ in natural languages. These are the fundamental building blocks of the program.
They are also known as lexical units.
C++ has five types of tokens
KEYWORDS
IDENTIFIERS
LITERALS
PUNCTUATORS
OPERATORS
1. KEYWORDS
These are the words that convey a special meaning to the language compiler.
These are reserved for special purpose and must not be used as normal identifier names.
It cannot be redefined for any other purposes.
Some of the KEYWORDs are…
auto, break, case, char, class, const, continue, default, delete, do, double, else, enum, extern, float, for, friend, goto, if, inline, int, long, new, private, switch, this, void, while…..
2. IDENTIFIERS
These are user-defined (key)words that are used to name different program elements such as memory locations (variable), statements, functions, objects, classes etc.
The identifiers of memory locations are called variables.
The identifiers assigned to statements are called labels.
The identifiers used to refer a set of statements are called function names.
Rules for constructing IDENTIFIERS
It is an arbitrary long sequence of letters, digits and underscores(_)
The first letter must be an alphabet or underscore
White space and special characters are not allowed.
Keywords cannot be used as identifiers.
Upper and lower case letters are treated differently, i.e., C++ is case sensitive lang.
3. LITERALS
These are data items that never change their value during a program run.
It is also referred to as constants
Different types of LITERALS are…
Integer-constants or literals
Floating point- (real)constants or literals
Character-constants or literals
String-constants or literals
I. INTEGER CONSTANT
These are WHOLE NUMBERS WITHOUT ANY FRACTIONAL PART.
C++ allows three types of integer constant
Decimal – eg:- 123, +97
Octal - eg:- 0123, 010
Hexa-Decimal – eg:- 0x14, 0XC
Characteristics of integer literals
It must have at least one digit and must not contain any decimal point.
It may contain either + or – sign as the first character, which indicates whether the number is positive or negative.
A number with no sign is treated as positive.
No other characters are allowed.
II. FLOATING CONSTANT
It is also called real constants
These are numbers having fractional parts
These may be written in one of the two forms called
Fractional form
Exponent form
eg:- 2.0, 17.23, - 45.23
eg:- 172E08, 1.72E-07(or 172.0 X 108 , 1.72 X 10-7 )
Characteristics of real constants (fractional form)
It is in fractional form must have at least one digit and a decimal point.
It may contain either + or – sign preceding it.
A number with no sign is treated as positive
Characteristics of real constants (Exponent form)
It is in exponent form has two parts:
a mantissa, and a exponent.
The mantissa must be either an integer or a valid fractional form.
The mantissa is followed by a letter E or e and the exponent.
The exponent must be an integer.
III. CHARACTER CONSTANT
It is one character enclosed in single quotes that never changes its value during the program run.
eg:- ‘a’, ‘1’
The value of a single character constant is the ASCII value of the character.
eg:- The value of ‘A’ will be the ASCII value 65.
Escape sequences
Escape sequence represents a single character (Eg. ‘\n’, ‘\t’, ‘\\’, etc.)
C++ language has certain non-graphic character constants, which cannot be typed directly from the keyboard. Eg. Enter key, tab key, backspace etc.
These non-graphic symbols can be represented by using escape sequences, which consists of a backslash followed by one or more characters.
IV. STRING CONSTANT
It is a sequence of one or more characters surrounded by double quotes.
eg:- “a”, “123”, “hello welcome”
Each string literal is by default (automatically) added with a special character ‘\0’ which makes the end of a string
eg:- “a”, “123”, “hello welcome”
Each string literal is by default (automatically) added with a special character ‘\0’ which makes the end of a string
4. PUNCTUATORS
The C++ has some special symbols that have syntactic or semantic meaning to the compiler.
The following characters are used as punctuators (also known as separators).[ ] ( ) { } , . ; : * # ‘ “
5. OPERATORS
C++ has rich collection of operators.
It is a symbol that tells the compiler about a specific operation.The operator is applied on a set of data is called operands.
C++ provides different types of operators like
Arithmetic, Relational, Logical, Assignment, Conditional, etc.
eg:- [+ - / * % ] , [< <= > >= ==]
This is just a basic note. Subscribe for getting more updates
©Coders World
Comments
Post a Comment