1 DATA TYPES
- C++ support all data type of C(char, int, float, double)
- C++ introduced two new data types(bool and string)
2 TYPES OF VARIABLE
- Local : Variable declared inside function.
- Global : Variable declared in global space.
- Data Member : Variable declared inside class.
3 PROGRAMMING TOKEN
- Literals are contant values for variables.
- C has 32 keywords.
- $(dollar) and _(underscore) allowed for identifiers
- const keyword is use to declare constant.
- inline functions are improved form of MACROS.
4 OPERATORS
- TYPEs: Unary, Binary, Ternary
- Precedence: Order of evaluation in expression.
- Associativity: Direction of evaluation in expression.
- Relational Expression always returns 0(false) or 1(true)
5 CONDITIONAL STATEMENTS
- Statements associated with if block executes iff the condition return true(non-zero).
- Statements associated with else block executes iff the condition return false(zero).
- Switch cases are use when we have finite set of option with fix values, usefull for menu driven programs.
- break is use to control the fall through of switch cases.
6 LOOPING STATEMENTS
- while and for are entry control loops.
- do-while is exit control loop.
- Loop executes till the condition returns true(non-zero).
- break - stop execution & terminate the loop.
- continue - stop execution & continue the loop.
7 FUNCTIONS
- Implementation of modular programming approach.
- Most important benifit is code reusability.
- Function Elements: prototype, definition, calling.
- Function Content: name, return_type, argument_list, body.
8 POINTER and REFERENCE
- Pointers use to store the address of another variable.
- Reference variable is alias of existing variable.
- * operator is use to declare pointer type variable.
eg : int *p;
- & operator is use to access address.
eg : int *p = & x;
- & operator is also use to declare reference type variable.
eg : int &r = x;
- * operator is also use to de-refrencing.
eg : int v = *p;
9 ARRAYS
- Collection of similar data elements.
- Allocates contigous memory space.
- Access with index i.e 0 <= index < size
- Usefull to store related data elements.
10 STRING
- Collection of characters are called string.
- String is character array in C.
- Always ends with '\0'(NULL Character).
- Functionality suported by string.h header file.
- string is also a class in C++.
- String class is declared in std namespace.
eg: string str = "Prowess";
11 C++ I/O
- C++ Input-Output is stream based.
- Stream is a sequence of bytes.
- cin is an object of istream class.
- cout is an object of ostream class.
- cout use insertion operator( << )
- cin use extraction operator( >> )
12 NAMESPACE
- Namespace is a declerative region that provides a scope.
- Namespaces are use to organise code into logical groups.
- Namespace provide prevention from name collision.
- C++ provides namespace keyword to create named region/block.
13 FUNCTION OVERLOADING
- Function Overloading allows you to create more than one function with the same name in same scope.
- Each function must have unique argument list.
- It is optional to change return type in overloading.
- Function can be overload by :
1. Changing number of argument.
2. Changing type of argument.
3. Changing order of argument.
14 FEATURES ADDED FROM C++
- NAMESPACE : namespace represents named code block that provide scope.
- REFERENCE : reference variables are alias of existing variable.
int &r = x;
- INLINE FUNCTION : inline function removes calling overhead.
eg : inline int square(int m){ return m*m; }
- DEFAULT ARGUMENT: in C++ we can pass default value to function argument at definition time.
eg : int mul(int x, int y=2){ //body }
- new KEYWORD : use for dynamic memory allocation.
- delete KEYWORD : use for de-allocation of memory.
- TEMPLATE : templates are use for writing generic codes(functions,classes).
15 CLASS & OBJECT
- Class is act as a blueprint for objects.
- Class is user-defined data type.
- Class contains :
1. Data,
2. Functions,
3. Constructor,
4. Destructor
5. Nested Classes
- Object is a physical representation of class description.
- Object is real world entity.
- Programming Objects must have unique identity.
16 ACCESS SPECIFIERS
- C++ supports 3 access modes for class:
- public : member can be access anywhere.
- private : member can be only access inside class.
- protected: member can be access in same class and also in derived class.
17 FRIEND KEYWORD
- A class can declare any function or class as their friend.
- Friend class or function can access all the members(public,private,proteced) of the class that declare them as their friend.
- Friend function are not member function.
18 STATIC KEYWORD
- static data member are shared variable.
- static data member have only one copy in memory.
- static function can not access not-static members of class.
- static members are object independent.
- static members can be access by using class name.
eg : CLASS_NAME :: member;
19 CONSTRUCTOR & DESTRUCTOR
- They are special member function of class.
- Constructor have same name as class-name.
- Construtor automatically invoke at object construction time to set the values for object.
- Constructor can be overload.
- There are three types of Constructor:
1. Default Constructor.
2. Parameterised Constructor.
3. Copy Constructor
- Destructor also have same name as class-name with prefix tilde symbol(~)
- Destructor also invoked automatically just before the object unload from memory for de-allocation of resources accupied by that object.
- Destructor can not be overload.
20 OOPS CONCEPTS
- ENCAPSULATION : Wrapping data and behaviour together into a single unit.
- ABSTRACTION : Representing only essential features without including the background details.
- INHERITANCE : Allow a class to aquire the properties of other class.
- POLYMORPHISM : Capablity to perform same behaviour in multiple ways.
21 OTHER TRICKY CONCEPTS
- VIRTUAL BASE CLASS : Use to solve the diamond problem of multiple inheritance.
- PURE VIRTUAL FUNCTION : In base class function with no body/definition.
- ABSTRACT CLASS : A base class contains 1 or more pure virtual function. Abstract classes can not be instantiated.
- VIRTUAL DESTRUTOR : In base class we declare destructor as virtual for proper invocation of destructor in case of upcasting(base pointer holds the address of derived class object).
- this POINTER : In all non-static functions of a class this pointer is implicitly available and represents current object.
22 FILE HANDLING
- File is use to store program data on permanent storage medium.
- C++ supports stream base file input and output.
- ofstream class is use for writing data on files.
- ifstream class is use for reading data from files.
- streams are cloaseble, provides close() function to free file resource.
- get() and put() functions perform character by character read/write.
- read() and write() functions use for binary operation on file.
23 EXCEPTION HANDLING
- Exceptions are abnormal situation during the execution of code that disrupt the normal flow of our program.
- C++ provide try, catch, throw keywords for Exception handling.
- throw : throw keyword is use to raise the exception situation in program,this process is known as throwing an exception.
- try : try keyword use to create try block that contains the set of codes/statements that may cause exception during runtime.
- catch : catch blocks are handler blocks,if exception accurs in try-block then the control jumps in catch block to handle the exception.
24 TEMPLATES
- Templates basically use to write generic programming in C++.
- Template code allows to work with different data-types.
- C++ provide template keyword for writing generic classes and generic functions.
- Template classes or functions, allows to work with different data type without re-writing the code for each type.