Introduction To
C++
according to 2016 IEEE spectrum Top Programming Language ranking, C++ ranks 4th which suggests that Learning C++ is a wise investment for all programmers.
C++ is a statically-typed, free-form, (usually) compiled, multi-paradigm, intermediate-level general-purpose middle-level programming language.
Many of today’s operating systems, system drivers, browsers and games use C++ as their core language. This makes C++ one of the most popular languages today.
History of C++
While Bjarne Stroustrup was working in AT&T Bell Labs in 1979, he faced difficulties in analyzing UNIX kernel for distributed systems. The current languages were either too slow or too low level. So, he set forward to create a new language.
For building this language, he chose C. Why C? Because it is a general purpose language and is very efficient as well as fast in its operations.
He used his knowledge of object-oriented model from SIMULA and began working on class extensions to C. His aim was to create a language with far higher level of abstraction while retaining the efficiency of C.
This new programming language was named C withClasses, but was later renamed to C++ (++ refers to the increment operator in C).
C++98
When C++ was first released in 1985, there were no official standards released. It was only until 1998 that C++ was first standardized which was known as C++98.
C++03
In 2003, a new version of C++ standard was published. C++03 wasn’t really a new standard altogether but a bug fix release identified with C++98 “to ensure greater consistency and portability”.
C++11 (C++0x)
The next major standard for C++ was released in 2011 and it was named C++11. Since, C++ committee was sure this update would be released within 2009, they unofficially named it C++0x. Later, when they didn’t, Stroustrup joked that C++0x went hexadecimal - C++0xB (C++11). Nice save.
C++14 (C++1y)
C++14 is the current iteration of C++ released in 2014. Like C++03, it included mainly bug fixes and simple improvements to C++11.
C++17 (C++1z)
The supposedly next iteration to C++ which is planned to be rolled out in 2017. It is expected to have many new features. Most of the features planned for this version are already completed.
What you will learn in this course:
Basics
- Setting up C++ Development Environment
- Writing first C++ program : Hello World example
- Is it fine to write “void main()” or “main()” in C/C++?
- C++ Data Types
- What happen when we exceed valid range of built-in data types in C++?
- C/C++ Preprocessors
- Loops in C and C++
- Decision Making in C / C++ (if , if..else, Nested if, if-else-if )
- Execute both if and else statements in C/C++ simultaneously
- How to compile 32-bit program on 64-bit gcc in C and C++
- Switch Statement in C/C++
C vs C++
- Write a C program that won’t compile in C++
- Undefined Behavior in C and C++
- Name Mangling and extern “C” in C++
- How does “void *” differ in C and C++?
- Write a program that produces different results in C and C++
- Type difference of character literals in C and C++
- Difference between C structures and C++ structures
Input and output
- I/O Redirection in C++
- Clearing The Input Buffer In C/C++
- Basic Input / Output in C++
- endl vs in C++
- Problem with scanf() when there is fgets()/gets()/scanf() after it
- How to use getline() in C++ when there are blank lines in input?
- scanf() and fscanf() in C – Simple Yet Poweful
- Using return value of cin to take unknown number of inputs in C++
- How to change the output of printf() in main() ?
- Implementation of a Falling Matrix
- What does buffer flush means in C++ ?
- kbhit in C language
- Code to generate the map of India (with explanation)
Operators
- Operators in C / C++
- Unary operators in C/C++
- Conditionally assign a value without using conditional and arithmetic operators
- Execution of printf with ++ operators
- Set a variable without using Arithmetic, Relational or Conditional Operator
- Scope Resolution Operator Versus this pointer in C++?
- Pre-increment (or pre-decrement) in C++
- CHAR_BIT in C
- const_cast in C++ Type Casting operators
Arrays and Strings
- Arrays in C/C++
- Array of Strings in C++ (3 Different Ways to Create)
- Multidimensional Arrays in C / C++
- Raw string literal in C++
- Counts of distinct consecutive sub-string of length two using C++ STL
- Converting string to number and vice-versa in C++
- How to find size of array in C/C++ without using sizeof ?
- Different methods to reverse a string in C/C++
- Tokenizing a string in C++
- getline() function and character array
- Convert string to char array in C++
- C++ string class and its applications
- C++ String Class and its Applications Set 2
- How to create a dynamic 2D array inside a class in C++ ?
- Lexicographically next permutation in C++
- How to print size of array parameter in C++?
- How to split a string in C/C++, Python and Java?
- stringstream in C++ and its applications
- strrchr() function in C/C++
- isspace() in C/C++ and its application to count whitespace characters
- char* vs std:string vs char[] in C++
- lexicographical_compare() in C++
- string at() in C++
- Substring in C++
- std::stol() and std::stoll() functions in C++
- strchr() function in C++ and its applications
- strcat() vs strncat() in C++
- strncat() function in C/C++
- strpbrk() in C
- strcoll() in C/C++
- Why strcpy and strncpy are not safe to use?
Functions
- Functions in C/C++
- Default Arguments in C++
- C function argument and return values
- Inline Functions in C++
- Return from void functions in C++
- std::tuple, std::pair Returning multiple values from a function using Tuple and Pair in C++
- A C/C++ Function Call Puzzle
- Functors in C++
- Ceil and Floor functions in C++
- Const member functions in C++
- atol(), atoll() and atof() functions in C/C++
- swap() in C++
- wmemmove() function in c++
- wcscat() function in C++
- difftime() function in C++
- asctime() function in C++
- localtime() function in C++
- scalbn() function in C++
- isunordered() function in C++
- isnormal() in C++
- isinf() function in C++
- ctime() Function in C/C++
- clock() function in C/C++
- nearbyint() function in C++
- quick_exit() function in C++ with Examples
- wcscmp() function in C++ with Examples
- wcscpy() function in C++ with Examples
- wcslen() function in C++ with Examples
Pointers and References
- Pointers in C and C++ Set 1 (Introduction, Arithmetic and Array)
- What is Array Decay in C++? How can it be prevented?
- Opaque Pointer
- References in C++
- Can references refer to invalid location in C++?
- When do we pass arguments by reference or pointer?
- Smart Pointers in C++
- ‘this’ pointer in C++
- Type of ‘this’ pointer in C++
- “delete this” in C++
- auto_ptr, unique_ptr, shared_ptr and weak_ptr
- Dangling, Void , Null and Wild Pointers
- Passing by pointer Vs Passing by Reference in C++
- NaN in C++ – What is it and how to check for it?
- Understanding nullptr in C++
- Pointers vs References in C++
Dynamic memory allocation
Object Oriented Programming(OOP)
- OOPs Object Oriented Design
- Basic Concepts of Object Oriented Programming using C++
- C++ Classes and Objects
- Access Modifiers in C++
- Inheritance in C++
- Polymorphism in C++
- Encapsulation in C++
- Abstraction in C++
- Structure vs class in C++
- Can a C++ class have an object of self type?
- Why is the size of an empty class not zero in C++?
- Static data members in C++
- Some interesting facts about static member functions in C++
- Friend class and function in C++
- Local Classes in C++
- Nested Classes in C++
Constructor and Destructor
- Constructors in C++
- Copy Constructor in C++
- Destructors in C++
- Does C++ compiler create default constructor when we write our own?
- When should we write our own copy constructor?
- When is copy constructor called?
- Initialization of data members
- Use of explicit keyword in C++
- When do we use Initializer List in C++?
- Private Destructor
- Playing with Destructors in C++
- Copy elision in C++
- C++ default constructor Built-in types
- When does compiler create default and copy constructors in C++?
- Why copy constructor argument should be const in C++?
- C++ Internals Default Constructors Set 1
- When are static objects destroyed?
- Is it possible to call constructor and destructor explicitly?
Function Overloading
Operator Overloading
- Operator Overloading in C++
- Copy constructor vs assignment operator in C++
- When should we write our own assignment operator in C++?
- What are the operators that can be and cannot be overloaded in C++?
- Advanced C++ Conversion Operators
- Is assignment operator inherited?
- Default Assignment Operator and References
- Overloading stream insertion (<>) operators in C++
- Overloading Subscript or array index operator [] in C++
Virtual Functions
- Default arguments and virtual function
- Virtual functions in derived classes
- Can static functions be virtual in C++?
- Virtual Destructor
- Advanced C++ Virtual Constructor
- Advanced C++ Virtual Copy Constructor
- RTTI (Run-time type Information) in C++
- Can virtual functions be private in C++?
- Can virtual functions be inlined?
- Pure Virtual Functions and Abstract Classes in C++
- Pure virtual destructor in C++
Exception Handling
Namespace
Standard Template Library (STL)
- The C++ Standard Template Library (STL)
- Sort in C++ Standard Template Library (STL)
- Binary Search in C++ Standard Template Library (STL)
- Pair in C++ Standard Template Library (STL)
- Vector in C++ STL
- List in C++ Standard Template Library (STL)
- Deque in C++ Standard Template Library (STL)
- deque::empty() and deque::size() in C++ STL
- deque::front() and deque::back() in C++ STL
- deque::clear() and deque::erase() in C++ STL
- Queue in Standard Template Library (STL)
- queue::front() and queue::back() in C++ STL
- queue::push() and queue::pop() in C++ STL
- queue::empty() and queue::size() in C++ STL
- Priority Queue in C++ Standard Template Library (STL)
- Stack in C++ STL
- stack push() and pop() in C++ STL
- forward_list::push_front() and forward_list::pop_front() in C++ STL
- stack top() in C++ STL
- stack empty() and stack size() in C++ STL
- Set in C++ Standard Template Library (STL)
- std::next_permutation and prev_permutation in C++
- std::stoul and std::stoull in C++
- shuffle vs random_shuffle in C++
- Difference between set, multiset, unordered_set, unordered_multiset
- Check if a key is present in a C++ map or unordered_map
- std::stable_partition in C++
- std::slice (Valarray slice selector)
- std::memchr in C++
- std::strncmp() in C++
- stable_sort() in C++ STL
- std::memcmp() in C++
- memset in C++
- bucket_count and bucket_size in unordered_map in C++
- Map of pairs in STL
- Range-based for loop in C++
- std::includes() in C++ STL
- set_symmetric_difference in C++ with Examples
- sort_heap function in C++
- map vs unordered_map in C++
- round() in C++
- Multiset in C++ Standard Template Library (STL)
- Map in C++ Standard Template Library (STL)
- Heap in C++ STL make_heap(), push_heap(), pop_heap(), sort_heap(), is_heap, is_heap_until()
- std::sort() in C++ STL
- Strand Sort
- Type Inference in C++ (auto and decltype)
- std::transform() in C++ STL (Perform an operation on all elements)
- Variadic function templates in C++
- Template Specialization in C++
- Implementing Iterator pattern of a single Linked List
- Binary Search functions in C++ STL (binary_search, lower_bound and upper_bound)
- Descending order in Map and Multimap of C++ STL
- Insertion and Deletion in STL Set C++
- set::key_comp() in C++ STL
- set value_comp() function in C++ STL
- unordered_set get_allocator() in C++ STL with Examples
- Multimap in C++ Standard Template Library (STL)
- map emplace() in C++ STL
- multimap::emplace_hint() in C++ STL
- multimap::emplace() in C++ STL
- multimap::count() in C++ STL
- multimap find() in C++ STL
- multimap::erase() in C++ STL
- multimap::begin() and multimap::end() in C++ STL
- multimap::cbegin() and multimap::cend() in C++ STL
- map cbegin() and cend() function in C++ STL
- multimap::crbegin() and multimap::crend() in C++ STL
- multimap size() function in C++ STL
- multimap lower_bound() function in C++ STL
- multimap swap() function in C++ STL
- multimap upper_bound() function in C++ STL
- multimap maxsize() in C++ STL
- multimap insert() in C++ STL
- multimap equal_range() in C++ STL
- sinh() function in C++ STL
- cosh() function in C++ STL
- tanh() function in C++ STL
- acos() function in C++ STL
- asinh() function in C++ STL
- acosh() function in C++ STL
- atanh() function in C++ STL
C++ Library
- random header in C++ Set 1(Generators)
- random header Set 2 (Distributions)
- Array Type Manipulation in C++
- C++ programming and STL facts
- sqrt, sqrtl and sqrtf in C++
- std::stod, std::stof, std::stold in C++
- C program to demonstrate fork() and pipe()
- Complex numbers in C++ Set 1
- Complex numbers in C++ Set 2
- Inbuilt library functions for user Input scanf, fscanf, sscanf, scanf_s, fscanf_s, sscanf_s
- rename function in C/C++
- Chrono in C++
- std:: valarray class in C++
- C++ Floating Point Manipulation (fmod(), remainder(), remquo() … in cmath)
- Character Classification in C++ : cctype
- snprintf() in C library
- boost::split in C++ library
- Modulus of two float or double numbers
- is_trivial function in C++
- Array sum in C++ STL
- div() function in C++
- exit() vs _Exit() in C and C++
- std::none_of in C++
- isprint() in C++
- iscntrl() in C++ and its application to find control characters
- partition_point in C++
- Iterator Invalidation in C++
- fesetround() and fegetround() in C++ and their application
- rint(), rintf(), rintl() in C++
- hypot(), hypotf(), hypotl() in C++
- std::gslice Valarray generalized slice selector
- std::setbase, std::setw , std::setfill in C++
- strxfrm() in C/C++
- Set position with seekg() in C++ language file handling
- strstr() in C/C++
- difftime() C library function
- Socket Programming in C/C++
- Precision of floating point numbers in C++ (floor(), ceil(), trunc(), round() and setprecision())
- <bits/stdc++.h> in C++
- std::string class in C++
- Merge operations using STL in C++ merge(), includes(), set_union(), set_intersection(), set_difference(), ., inplace_merge,
- std::partition in C++ STL
- Ratio Manipulations in C++ Set 1 (Arithmetic)
- Ratio Manipulations in C++ Set 2 (Comparison)
- numeric header in C++ STL Set 1 (accumulate() and partial_sum())
- numeric header in C++ STL Set 2 (adjacent_difference(), inner_product() and iota())
- Bind function and placeholders in C++
- Array class in C++
- Tuples in C++
- std::regex_match, std::regex_replace() Regex (Regular Expression) In C++
- Common Subtleties in Vector STLs
- Understanding constexpr specifier in C++
- unordered_multiset and its uses
- unordered_multimap and its application
- std::fill() and fill_n() in C++ STL
- Writing OS Independent Code in C/C++
- C Program to display hostname and IP address
- Database Connectivity using C/C++
- C++ bitset and its application
- unordered_map in C++ STL
- unordered_set in C++ STL
- nextafter() and nexttoward() in C/C++
C++ Advanced
C++ in Competitive Programming
- Writing C/C++ code efficiently in Competitive programming
- Array algorithms in C++ STL (all_of, any_of, none_of, copy_n and iota)
- searching in fork()
- Data Type Ranges and their macros in C++
- Cin-Cout vs Scanf-Printf
- getchar_unlocked() – faster input in C/C++ for Competitive Programming
- C qsort() vs C++ sort()
- Middle of three using minimum comparisons
- Check for integer overflow on multiplication
- Generating Test Cases (generate() and generate_n() in C++)
Puzzles
- Can we call an undeclared function in C++?
- Can we access global variable if there is a local variable with same name?
- Can we use function on left side of an expression in C and C++?
- Can we access private data members of a class without using a member or a friend function?
- How to make a C++ class whose objects can only be dynamically allocated?
- How to print “GeeksforGeeks” with empty main() in C, C++ and Java?
- Print 1 to 100 in C++, without loop and recursion
- C/C++ Tricky Programs
- Print a number 100 times without using loop, recursion and macro expansion in C?
- How to restrict dynamic allocation of objects in C++?
- Program for Sum the digits of a given number
- Write a URL in a C++ program
- A creative C++ program to Zoom digits of an integer
- Composite Design Pattern in C++
- Programming puzzle (Assign value without any control statement)
- Programs for printing pyramid patterns in C++
- Swap two variables in one line in C/C++, Python, PHP and Java
- C/C++ program to shutdown a system
Interview Questions
Containers
- Ways to copy a vector in C++
- Sorting 2D Vector in C++ Set 3 (By number of columns)
- Sorting Vector of Pairs in C++ Set 2 (Sort in descending order by first and second)
- Sorting 2D Vector in C++ Set 2 (In descending order by row and column)
- 2D vector in C++ with user defined size
- vector erase() and clear() in C++
- Passing vector to a function in C++
- vector::push_back() and vector::pop_back() in C++ STL
- vector::empty() and vector::size() in C++ STL
- vector::front() and vector::back() in C++ STL
- Initialize a vector in C++ (5 different ways)
- Sorting 2D Vector in C++ Set 1 (By row and column)
- Sorting Vector of Pairs in C++ Set 1 (Sort by first and second)
- List in C++ Set 2 (Some Useful Functions)
- Forward List in C++ Set 1 (Introduction and Important Functions)
- Forward List in C++ Set 2 (Manipulating Functions)
- list::remove() and list::remove_if() in C++ STL
- forward_list::front() and forward_list::empty() in C++ STL
- forward_list::unique() in C++ STL
- forward_list::before_begin() in C++ STL
- forward_list::cbefore_begin() in C++ STL
- forward_list::reverse() in C++ STL
- forward_list::max_size() in C++ STL
- forward_list::splice_after() in C++ STL
- list::empty() and list::size() in C++ STL
- list::front() and list::back() in C++ STL
- list::pop_front() and list::pop_back() in C++ STL
- list::push_front() and list::push_back() in C++ STL
- list push_front() function in C++ STL
- list pop_back() function in C++ STL
- list pop_front() function in C++ STL
- list reverse function in C++ STL
- list resize() function in C++ STL
- list size() function in C++ STL
- list max_size() function in C++ STL
- Count number of unique Triangles using STL Set 1 (Using set)
- std::istream_iterator and std::ostream_iterator in C++ STL
Inheritance
- What all is inherited from parent class in C++?
- Virtual Functions and Runtime Polymorphism in C++ Set 1 (Introduction)
- Multiple Inheritance in C++
- What happens when more restrictive access is given to a derived class method in C++?
- Object Slicing in C++
- Hiding of all overloaded methods with same name in base class
- Inheritance and friendship
- Simulating final class in C++