SlideShare a Scribd company logo
Introduction to C++
C++ is a powerful and versatile programming language used to
develop various applications, including games, web browsers, and
operating systems.
Basics of C++ programming language
Data types and
variables
Understanding data types
and variables is
fundamental to writing
efficient and error-free C++
code.
Control flow statements
Learn about the various
control flow statements
such as if, else, switch, and
loops.
Functions in C++
Explore the concept of
functions and how to
create and use them in C++.
Data types and variables in C++
1 Integer
Used for whole numbers
2 Boolean
Represents true or false
3 Float
Used for decimal numbers
4 Character
Stores single character
Variables : https://www.w3schools.com/cpp/cpp_variables.asp
Data Types : https://www.w3schools.com/cpp/cpp_data_types.asp
Operators
An operator is a symbol that operates on a value to perform specific mathematical or logical
computations. They form the foundation of any programming language. In C++, we have
built-in operators to provide the required functionality.
Operators in C++ can be classified into 6 types
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Ternary or Conditional Operators
Arithmetic Operators
Arithmetic Operators can be classified into 2 Types:
A) Unary Operators: These operators operate or work with a single operand. For example:
Increment(++) and Decrement(–) Operators.
a++ is 10
++a is 12
b-- is 15
--b is 13
Binary Operators: These operators operate or work with two operands.
For example: Addition(+), Subtraction(-), etc.
Relational Operators
These operators are used for the comparison of the values of two operands. For example, ‘>’
checks if one operand is greater than the other operand or not, etc. The result returns a
Boolean value, i.e., true or false
Logical Operators
These operators are used to combine two or more conditions or constraints or to
complement the evaluation of the original condition in consideration. The result returns a
Boolean value, i.e., true or false.
Bitwise Operators
These operators are used to perform bit-level operations on the operands. The operators are
first converted to bit-level and then the calculation is performed on the operands.
Mathematical operations such as addition, subtraction, multiplication, etc. can be performed
at the bit level for faster processing.
Assignment Operators
These operators are used to assign value to a variable. The left side operand of the
assignment operator is a variable and the right side operand of the assignment operator is a
value. The value on the right side must be of the same data type as the variable on the left
side otherwise the compiler will raise an error.
Control flow statements in C++
Selection
Using if, else, if-else.
Iterations
Using for, while, and do-while loops
Jump
Using break, and continue statements
IF Statement
When you know exactly how many times you want to loop through a block of code
Syntax
if(condition)
{
// Statements to execute if
// condition is true
}
Working of IF statement
Working of if statement in C++
1. Control falls into the if block.
2. The flow jumps to Condition.
3. Condition is tested.
1. If Condition yields true, goto Step 4.
2. If Condition yields false, goto Step 5.
4. The if-block or the body inside the if is executed.
5. Flow steps out of the if block.
Example 1
Program demonstrates the use of if statement .
• C++
#include using namespace std;
int main() { int i = 10;
if (i < 15) {
cout << "10 is less than 15 n";
}
cout << "I am Not in if";
}
if else Statement
The if statement alone tells us that if a condition is true it will execute a block of statements
and if the condition is false it won’t. But what if we want to do something else if the condition
is false.
Syntax
if (condition)
{
// Executes this block if
// condition is true
}
else
{
// Executes this block if
// condition is false
}
Example : Check the greatest of three numbers
Algorithm
Assume that a, b, and c are three given numbers:
If ( a < b ) evaluates to true, then
1. If ( c < b ) is true, then b is greatest.
2. else c is greatest.
If ( a < b ) evaluates to false, then
1. If ( c < a ) is true, then a is greatest.
2. else c is greatest.
Implementation
#include using namespace std;
int main() { // Assume that a, b, and c are three given numbers
int a, b, c;
cout << "Enter three numbers: ";
cin >> a >> b >> c;
if (a < b) {
if (c < b) {
cout << "The greatest number is: " << b << endl;
} else {
cout << "The greatest number is: " << c << endl;
}
} else {
if (c < a) {
cout << "The greatest number is: " << a << endl;
} else {
cout << "The greatest number is: " << c << endl;
}
}
return 0;
}
Working of if else statement
Working of if-else statement
1. Control falls into the if block.
2. The flow jumps to Condition.
3. Condition is tested.
1. If Condition yields true, goto Step 4.
2. If Condition yields false, goto Step 5.
4. The if-block or the body inside the if is executed.
5. The else block or the body inside the else is executed.
6. Flow exits the if-else block.
Example :
Program demonstrates the use of if else statements.
// C++ program to illustrate if-else statement
#include using namespace std;
int main() { int i = 20;
// Check if i is 10
if (i == 10)
cout << "i is 10";
// Since is not 10
// Then execute the else statement
else
cout << "i is 20n";
cout << "Outside if-else block";
return 0;
}
Nested if-else Statement
Nested if-else statements are those statements in which there is an if statement inside
another if else. We use nested if-else statements when we want to implement multilayer
conditions(condition inside the condition inside the condition and so on).
Syntax of Nested if-else
if(condition1)
{
// Code to be executed
if(condition2)
{
// Code to be executed
}
else
{
// Code to be executed
}
}
else
{
// code to be executed
}
Jump statements
Jump statements are used to manipulate the flow of the program if some conditions are met.
It is used to terminate or continue the loop inside a program or to stop the execution of a
function.
Types of Jump Statements in C++
In C++, there is four jump statement
1. break
2. continue
continue in C++
The C++ continue statement is used to execute other parts of the loop while skipping some
parts declared inside the condition, rather than terminating the loop, it continues to execute
the next iteration of the same loop. It is used with a decision-making statement which must
be present inside the loop.
// C++ program to demonstrate the
// continue statement
// Driver code
int main() { for (int i = 1; i < 10; i++) {
if (i == 5)
continue;
cout << i << " ";
}
return 0;
}
break in C++
The C++ break statement is used to terminate the whole loop if the condition is met. Unlike
the continue statement after the condition is met, it breaks the loop and the remaining part
of the loop is not executed.
The break statement is used with decision-making statements such as if, if-else, or switch
statement which is inside the for loop which can be for loop, while loop, or do-while loop. It
forces the loop to stop the execution of the further iteration.
// C++ program to demonstrate the
// break statement
// Driver Code int main() { for (int i = 1; i < 10; i++) {
// Breaking Condition
if (i == 5)
break;
cout << i << " ";
}
return 0;
}
Loops
In Programming, sometimes there is a need to perform some operation more than once or
(say) n number of times. Loops come into use when we need to repeatedly execute a block
of statements.
For example: Suppose we want to print “Hello World” 10 times.
// C++ program to Demonstrate the need of loops
#include <iostream>
using namespace std;
int main()
{
cout << "Hello Worldn";
cout << "Hello Worldn";
cout << "Hello Worldn";
cout << "Hello Worldn";
cout << "Hello Worldn";
return 0;
}
Introduction to C++ programming language
for Loop
for loop is an entry-controlled loop that is used to execute a block of code repeatedly for
the specified range of values. Basically, for loop allows you to repeat a set of instructions for
a specific number of iterations.
The syntax of for loop in C++ is shown below:
for ( initialization; test condition; updation)
{
// body of for loop
}
Introduction to C++ programming language
// C++ program to illustrate for
loop to print numbers from // 1 to
n
#include using namespace std;
int main() {
// initializing n (value upto which you want to print // numbers
int n = 5;
int i; // initialization of loop variable
for (i = 1; i <= n; i++)
{
cout << i << " ";
}
return 0;
}
While Loop
While Loop in C++ is used in situations where we do not know the exact number of
iterations of the loop beforehand. The loop execution is terminated on the basis of the test
condition. Loops in C++ come into use when we need to repeatedly execute a block of
statements. During the study of the ‘for’ loop in C++, we have seen that the number of
iterations is known beforehand, i.e. the number of times the loop body is needed to be
executed is known to us.
Syntax:
while (test_expression)
{
// statements
update_expression;
}
Do/While Loop
Loops come into use when we need to repeatedly execute a block of statements. Like while
the do-while loop execution is also terminated on the basis of a test condition. The main
difference between a do-while loop and a while loop is in the do-while loop the condition is
tested at the end of the loop body, i.e do-while loop is exit controlled whereas the other two
loops are entry-controlled loops.
Syntax:
do
{
// loop body
update_expression;
}
while (test_expression);
Introduction to C++ programming language
Functions in C++
1
Function Declaration
Declaring the function prototype
2 Function Definition
Implementing the function logic
3
Function Call
Using the function in the program
Functions
A function is a set of statements that takes input, does some specific computation, and
produces output. The idea is to put some commonly or repeatedly done tasks together to
make a function so that instead of writing the same code again and again for different
inputs, we can call this function.
In simple terms, a function is a block of code that runs only when it is called.

More Related Content

Similar to Introduction to C++ programming language (20)

PPT
C++basics
aamirsahito
 
PPT
c++basics.ppt
TatyaTope4
 
PPT
c++basiccs.ppt
RaghavendraMR5
 
PPT
c++basics.ppt
EPORI
 
PPT
c++basics.ppt
Infotech27
 
PPT
C++basics
JosephAlex21
 
PPTX
Lecture 1 Introduction C++
Ajay Khatri
 
PPTX
C_BASICS FOR C PROGRAMMER WITH SRIVATHS P
amankr1234am
 
PPTX
Object oriented programming system with C++
msharshitha03s
 
PDF
C++ STATEMENTS
Prof Ansari
 
PPTX
Computational Physics Cpp Portiiion.pptx
khanzasad009
 
PDF
Lecture1
Amisha Dalal
 
PPTX
LOOPS AND DECISIONS
Aami Kakakhel
 
PDF
chap2cpp4th.pdf
AsiimweGeraldMaserek1
 
PPT
Lecture 1
Mohammed Saleh
 
PPT
Lecture 1
Mohammed Saleh
 
PPTX
Switch case and looping kim
kimberly_Bm10203
 
PDF
C++ control structure
bluejayjunior
 
PPSX
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
PPSX
C++ Programming Language
Mohamed Loey
 
C++basics
aamirsahito
 
c++basics.ppt
TatyaTope4
 
c++basiccs.ppt
RaghavendraMR5
 
c++basics.ppt
EPORI
 
c++basics.ppt
Infotech27
 
C++basics
JosephAlex21
 
Lecture 1 Introduction C++
Ajay Khatri
 
C_BASICS FOR C PROGRAMMER WITH SRIVATHS P
amankr1234am
 
Object oriented programming system with C++
msharshitha03s
 
C++ STATEMENTS
Prof Ansari
 
Computational Physics Cpp Portiiion.pptx
khanzasad009
 
Lecture1
Amisha Dalal
 
LOOPS AND DECISIONS
Aami Kakakhel
 
chap2cpp4th.pdf
AsiimweGeraldMaserek1
 
Lecture 1
Mohammed Saleh
 
Lecture 1
Mohammed Saleh
 
Switch case and looping kim
kimberly_Bm10203
 
C++ control structure
bluejayjunior
 
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
C++ Programming Language
Mohamed Loey
 

Recently uploaded (20)

PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
PPT
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
PDF
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
PDF
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
PPTX
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
PPTX
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
PDF
Digital water marking system project report
Kamal Acharya
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPTX
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
Design Thinking basics for Engineers.pdf
CMR University
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
Digital water marking system project report
Kamal Acharya
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
Ad

Introduction to C++ programming language

  • 1. Introduction to C++ C++ is a powerful and versatile programming language used to develop various applications, including games, web browsers, and operating systems.
  • 2. Basics of C++ programming language Data types and variables Understanding data types and variables is fundamental to writing efficient and error-free C++ code. Control flow statements Learn about the various control flow statements such as if, else, switch, and loops. Functions in C++ Explore the concept of functions and how to create and use them in C++.
  • 3. Data types and variables in C++ 1 Integer Used for whole numbers 2 Boolean Represents true or false 3 Float Used for decimal numbers 4 Character Stores single character Variables : https://www.w3schools.com/cpp/cpp_variables.asp Data Types : https://www.w3schools.com/cpp/cpp_data_types.asp
  • 4. Operators An operator is a symbol that operates on a value to perform specific mathematical or logical computations. They form the foundation of any programming language. In C++, we have built-in operators to provide the required functionality. Operators in C++ can be classified into 6 types 1. Arithmetic Operators 2. Relational Operators 3. Logical Operators 4. Bitwise Operators 5. Assignment Operators 6. Ternary or Conditional Operators
  • 5. Arithmetic Operators Arithmetic Operators can be classified into 2 Types: A) Unary Operators: These operators operate or work with a single operand. For example: Increment(++) and Decrement(–) Operators. a++ is 10 ++a is 12 b-- is 15 --b is 13
  • 6. Binary Operators: These operators operate or work with two operands. For example: Addition(+), Subtraction(-), etc.
  • 7. Relational Operators These operators are used for the comparison of the values of two operands. For example, ‘>’ checks if one operand is greater than the other operand or not, etc. The result returns a Boolean value, i.e., true or false
  • 8. Logical Operators These operators are used to combine two or more conditions or constraints or to complement the evaluation of the original condition in consideration. The result returns a Boolean value, i.e., true or false.
  • 9. Bitwise Operators These operators are used to perform bit-level operations on the operands. The operators are first converted to bit-level and then the calculation is performed on the operands. Mathematical operations such as addition, subtraction, multiplication, etc. can be performed at the bit level for faster processing.
  • 10. Assignment Operators These operators are used to assign value to a variable. The left side operand of the assignment operator is a variable and the right side operand of the assignment operator is a value. The value on the right side must be of the same data type as the variable on the left side otherwise the compiler will raise an error.
  • 11. Control flow statements in C++ Selection Using if, else, if-else. Iterations Using for, while, and do-while loops Jump Using break, and continue statements
  • 12. IF Statement When you know exactly how many times you want to loop through a block of code Syntax if(condition) { // Statements to execute if // condition is true }
  • 13. Working of IF statement
  • 14. Working of if statement in C++ 1. Control falls into the if block. 2. The flow jumps to Condition. 3. Condition is tested. 1. If Condition yields true, goto Step 4. 2. If Condition yields false, goto Step 5. 4. The if-block or the body inside the if is executed. 5. Flow steps out of the if block.
  • 15. Example 1 Program demonstrates the use of if statement . • C++ #include using namespace std; int main() { int i = 10; if (i < 15) { cout << "10 is less than 15 n"; } cout << "I am Not in if"; }
  • 16. if else Statement The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false it won’t. But what if we want to do something else if the condition is false. Syntax if (condition) { // Executes this block if // condition is true } else { // Executes this block if // condition is false }
  • 17. Example : Check the greatest of three numbers Algorithm Assume that a, b, and c are three given numbers: If ( a < b ) evaluates to true, then 1. If ( c < b ) is true, then b is greatest. 2. else c is greatest. If ( a < b ) evaluates to false, then 1. If ( c < a ) is true, then a is greatest. 2. else c is greatest.
  • 18. Implementation #include using namespace std; int main() { // Assume that a, b, and c are three given numbers int a, b, c; cout << "Enter three numbers: "; cin >> a >> b >> c; if (a < b) { if (c < b) { cout << "The greatest number is: " << b << endl; } else { cout << "The greatest number is: " << c << endl; } } else { if (c < a) { cout << "The greatest number is: " << a << endl; } else { cout << "The greatest number is: " << c << endl; } } return 0; }
  • 19. Working of if else statement
  • 20. Working of if-else statement 1. Control falls into the if block. 2. The flow jumps to Condition. 3. Condition is tested. 1. If Condition yields true, goto Step 4. 2. If Condition yields false, goto Step 5. 4. The if-block or the body inside the if is executed. 5. The else block or the body inside the else is executed. 6. Flow exits the if-else block.
  • 21. Example : Program demonstrates the use of if else statements. // C++ program to illustrate if-else statement #include using namespace std; int main() { int i = 20; // Check if i is 10 if (i == 10) cout << "i is 10"; // Since is not 10 // Then execute the else statement else cout << "i is 20n"; cout << "Outside if-else block"; return 0; }
  • 22. Nested if-else Statement Nested if-else statements are those statements in which there is an if statement inside another if else. We use nested if-else statements when we want to implement multilayer conditions(condition inside the condition inside the condition and so on). Syntax of Nested if-else if(condition1) { // Code to be executed if(condition2) { // Code to be executed } else { // Code to be executed } } else { // code to be executed }
  • 23. Jump statements Jump statements are used to manipulate the flow of the program if some conditions are met. It is used to terminate or continue the loop inside a program or to stop the execution of a function. Types of Jump Statements in C++ In C++, there is four jump statement 1. break 2. continue
  • 24. continue in C++ The C++ continue statement is used to execute other parts of the loop while skipping some parts declared inside the condition, rather than terminating the loop, it continues to execute the next iteration of the same loop. It is used with a decision-making statement which must be present inside the loop.
  • 25. // C++ program to demonstrate the // continue statement // Driver code int main() { for (int i = 1; i < 10; i++) { if (i == 5) continue; cout << i << " "; } return 0; }
  • 26. break in C++ The C++ break statement is used to terminate the whole loop if the condition is met. Unlike the continue statement after the condition is met, it breaks the loop and the remaining part of the loop is not executed. The break statement is used with decision-making statements such as if, if-else, or switch statement which is inside the for loop which can be for loop, while loop, or do-while loop. It forces the loop to stop the execution of the further iteration.
  • 27. // C++ program to demonstrate the // break statement // Driver Code int main() { for (int i = 1; i < 10; i++) { // Breaking Condition if (i == 5) break; cout << i << " "; } return 0; }
  • 28. Loops In Programming, sometimes there is a need to perform some operation more than once or (say) n number of times. Loops come into use when we need to repeatedly execute a block of statements. For example: Suppose we want to print “Hello World” 10 times. // C++ program to Demonstrate the need of loops #include <iostream> using namespace std; int main() { cout << "Hello Worldn"; cout << "Hello Worldn"; cout << "Hello Worldn"; cout << "Hello Worldn"; cout << "Hello Worldn"; return 0; }
  • 30. for Loop for loop is an entry-controlled loop that is used to execute a block of code repeatedly for the specified range of values. Basically, for loop allows you to repeat a set of instructions for a specific number of iterations. The syntax of for loop in C++ is shown below: for ( initialization; test condition; updation) { // body of for loop }
  • 32. // C++ program to illustrate for loop to print numbers from // 1 to n #include using namespace std; int main() { // initializing n (value upto which you want to print // numbers int n = 5; int i; // initialization of loop variable for (i = 1; i <= n; i++) { cout << i << " "; } return 0; }
  • 33. While Loop While Loop in C++ is used in situations where we do not know the exact number of iterations of the loop beforehand. The loop execution is terminated on the basis of the test condition. Loops in C++ come into use when we need to repeatedly execute a block of statements. During the study of the ‘for’ loop in C++, we have seen that the number of iterations is known beforehand, i.e. the number of times the loop body is needed to be executed is known to us.
  • 35. Do/While Loop Loops come into use when we need to repeatedly execute a block of statements. Like while the do-while loop execution is also terminated on the basis of a test condition. The main difference between a do-while loop and a while loop is in the do-while loop the condition is tested at the end of the loop body, i.e do-while loop is exit controlled whereas the other two loops are entry-controlled loops.
  • 38. Functions in C++ 1 Function Declaration Declaring the function prototype 2 Function Definition Implementing the function logic 3 Function Call Using the function in the program
  • 39. Functions A function is a set of statements that takes input, does some specific computation, and produces output. The idea is to put some commonly or repeatedly done tasks together to make a function so that instead of writing the same code again and again for different inputs, we can call this function. In simple terms, a function is a block of code that runs only when it is called.