C++ Tutorial

C++ Introduction C++ is an object-oriented programming language. It was developed by Bjarne Stroustrup at AT&T Bell Laboratories. It is superset (extension) of C programming language. Depending upon features supported by programming languages, they are classified into two different categories: Object-based programming languages Object-oriented programming languages Object-based programming language The language that supports programming using objects is called object-based programming language. Important features of object-based programming languages are: Data encapsulation Data …

Read moreC++ Tutorial

C++ History

C++ is a middle-level programming language developed in 1980s by Bjarne Stroustrup at Bel Labs. C ++ development initially started in 1979, four years before its launch. It is started with name C with Classes not C++. In the end part of 1983, C with Classes was first used for AT&T’s internal programming needs. In the same year its name was changed to C++. C++ was not released commercially until the late part …

Read moreC++ History

C++ Installation

Let’s install C++ setup to start programming in C++. C++ setup contains C++ compiler which is required in your system. There are lots of C++ compilers available, you must choose according to your compatibility. List of C++ Compiler For Windows: Turbo C++ Microsoft Visual C++ Code::Blocks Borland C++ GCC For Linux: g++ For Mac OS: C++ Code::Block Apple XCode In this tutorial we prefer GCC compiler, which is compatible for both C and C++ programming. …

Read moreC++ Installation

C++ First Program

Let’s write a simple basic program structure of C++, its compilation and its execution (how it runs). This program is compiled using GCC compiler. Open any editor to write C++ program.

Output of above program

Compile and Run After writing C++ program, save the program with any name (first) with .cpp extension (first.cpp). Open any command prompt (MinGW Command Prompt) window and go to directory structure where C++ program file is saved. …

Read moreC++ First Program

C++ cin and cout

C++ Standard Input/Output C++ standard input/output operations are performed to flow bytes stream from keyboard (input device) to main memory and from main memory to display screen (output device) respectively. The input/output are done using standard libraries provided by C++. C++ I/O Library Header Files Library Description <iostream> This library defines cin, cout, cerr,and clog objects for input stream, output stream, un-buffered error stream, buffered error stream respectively. <fstream> This library defines file declares …

Read moreC++ cin and cout

C++ Data type

Data type in every language is very important. Data type means the different kind of data which are supported by a particular programming language. C++ programming language supports various kinds of data types. C++ data types are broadly classified into three categories. Built-in data types. Derived data types. User defined data types. C++ Built-in Data Types: int char void float double C++ Derived Data Types: array function pointer reference …

Read moreC++ Data type

C++ Variable

C++ variable are used to store data in memory location. The value stored in variable may be changed depends on program execution. Each variable in programming language has its own specific types. These specific data types determine the size and layout of the variable’s memory. Rules of C++ Variable Declaration: C++ variable name can be declared with small letters a-z, capital letters A-Z, digits 0-9, and underscore character. First …

Read moreC++ Variable

C++ operator

An operator is specially a symbol that tells compiler to perform specific manipulation. C++ contains various different types of operators. Types of C++ Operators Arithmetic Operators Logical Operators Relational Operators Assignment Operators Bitwise Operators Misc. Operators Arithmetic Operators Arithmetic operators are used to perform basic mathematical operation such as addition (+), subtraction (-), multiplication (*), division (/) etc. Let’s assume two variables A and B containing value 5 and …

Read moreC++ operator

C++ Keywords

Keywords are explicitly reserved identifier of C++ language features. It cannot be used as user-define program elements or other name for the program variables. C++ programming language has several reserved keywords used in program. ANSI C++ also uses the keywords available in ANSI C programming language.   ANSI C programming language keywords: auto double int struct break else long switch case enum register typedef char extern return union const float …

Read moreC++ Keywords

C++ OOPs Concepts

C++ Object-Oriented Programming Concepts C++ uses the concept of object-oriented programming. Object Oriented Programming has some prominent features: Object Class Data abstraction Encapsulation Polymorphism Inheritance Message passing   Object An object is the basic unit of object-oriented programming. It is a real-time entity. It can represent any item that the program has to handle. Declaration Syntax:


Here Fruit is class and mango is an object.   Class …

Read moreC++ OOPs Concepts

C++ If

C++ Control Statement C++ control statement or decision-making statement is used to control the flow of program statement according to condition applied.   C++ if Control Statement An if control statement in C++ is used to control the flow of program statement on behalf of condition applied. When if condition returns true boolean value, then statement within if block will be executed. And when if condition returns false boolean value, then statement after if the condition will …

Read moreC++ If

C++ Nested if

C++ nested if Control Statement Nested if control statement refers to if condition within if condition. C++ compiler checks nested if control statement when its parent if condition returns true, then the program is executed according to nested if condition. Syntax



← Prev Next→

C++ if-else

C++ if else Control Statement if else control statement in C++ is used to control the program flow in a two-way direction. When condition returns a true value, then the program executes if condition block otherwise program executes else block. Syntax:

C++ if else Example


← Prev Next→

C++ If-else-if

C++ if.. else if Control Statement if.. else if control statement is an if statement used with an optional else if control statement to check multiple conditions. In this control statement, when any one of condition returns true, then none of the other else if or else will be executed. Syntax

C++ if..else if Example


← Prev Next→

C++ Switch

C++ switch Control Statement The switch control statement allows checking the variable for equality against a list of values. The switch statement checks an integer, char or enumerated type in its condition expression. It does not take any floating variable in its condition expression. Syntax

C++ switch Example


← Prev Next→

C++ Break

C++ break Statement The break statement is used to alter the normal flow of a program. The break statement terminates a loop (for, while and do..while) and switch statement instantly where it applied. When a break statement is applied inside the nested loop, it only affects (breaks) the inner loop. Syntax

C++ break Example


← Prev Next→

C++ Continue

C++ continue Statement The continue statement forces to iterate the loop instantly without executing the next statement of the loop. Sometimes it is required to skip certain test condition within the loop, in such case continue statement is applied. When continue statement is applied inside the nested loop, it only affects (iterate) the inner loop. Syntax



← Prev Next→

C++ Goto

C++ goto Statement A goto statement is used to jump the flow of a sequence of program execution. It transfers the control to some other part of the program. The goto uses an identifier that encountered the control of program jumps to an identifier. Syntax

  Example This program calculates the average of numbers entered by the user. If the user enters a negative number, it ignores the number and calculates the …

Read moreC++ Goto

C++ For loop

C++ loop Statement A loop statement allows us to repeat the execution of a statement or group of statements multiple times. The statement(s) repeat execution within loop until the condition of loop became false. There are three types of loops in C++ programming language: for loop while loop do…while loop     C++ for Loop Statement The for loop is an iterative control statement. It executes loop’s statement(s) several times until the condition …

Read moreC++ For loop

C++ While loop

C++ while Loop Statement The while loop is an iterative control statement. A while loop repeatedly executes loop’s statement(s) several times as a given condition is true. Execution of loop is terminated when the condition of while loop becomes false and execute code after the loop. Syntax

  Working Process Of While Loop While loop first checks the condition applied. If the condition of a while loop is satisfied (true), statement(s) within the loop is executed. If …

Read moreC++ While loop