SlideShare a Scribd company logo
Overview of C++ language
Lecture’s outline

 What is C++?
 Identifiers.
 Constant
 Semicolons & Blocks in C++
 Data type
 Comments
 Operator
 Declaration of variables
 Giving value to variable
 C++ statements

                prepared by Taif.A.S.G
What is C++?
• Developed by Bjarne Stroustrup (in 1979 at Bell Labs)
• C++ is regarded as a middle-level language, as it comprises a
  combination of both high-level and low-level language features.
• C++ is a statically typed, compiled, general purpose, case-
  sensitive, free-form programming language that supports
  procedural, object-oriented, and generic programming.
• C++ is a superset of C that enhancement to the C language and
  originally named C with Classes but later it was renamed C++.

                         prepared by Taif.A.S.G
identifiers
They are used for naming classes
function, module, variables, object in a program.
They follow the following rules:
1) They can have alphabets , digits, and the underscore(_).
2) They must not begin with a digit.
3) Uppercase and lowercase are distinct.
4) They can be of any length.
5) It should not be a keyword.
6) White space is not allowed.

                      prepared by Taif.A.S.G
Constant
Constant is one whose value cannot be changed after it has
been initialized-any attempt to assign to field will produce a
compile-error .So, we can declare the constant by using
const field and use all uppercase letter.
Syntax of declare the constant is:
  const type name=value

Example:

const int STRENGTH = 100;
const float PI = 3.14;
                         prepared by Taif.A.S.G
Semicolons & Blocks in C++:
• In C++, the semicolon is a statement terminator.
  That is, each individual statement must be ended
  with a semicolon. It indicates the end of one logical
  entity.
• For example: following are two different
  statements:
  x = y;
  y = y+1;


                       prepared by Taif.A.S.G             6
Data type




prepared by Taif.A.S.G
Comments
C++ can use both the single line comments and multi-line
comments .
single line comments begin with // and end at the end of line.
For longer comments we can create multi-line comments by
starting with /* and ending with */




                        prepared by Taif.A.S.G
Operator
* / % + - are the mathematical operators
* / % have a higher precedence than + or –           mathematical
                                                     operators
 ++ Increment operator         –– Decrement operator
 ==    Equal (careful)
 !=            Not equal
 >=    Greater than or equal          Relational
 <=    Less than or equal             operators
 >     Greater than
 <     Less than
 &&    logical (sequential) and
                                       Logical
 ||    logical (sequential) or         operators
 =     assignment
                      prepared by Taif.A.S.G
Declaration of variables

The general form of declaration of variables:

           Type variable1, variable2,...., variableN;
Example:

int count;
float x,y;
double pi;
char c1,c2,c3;
byte b;
                         prepared by Taif.A.S.G
Giving value to variable

The general form of giving value to variables:

                  variableName= value;
Example:

finalValue=100;
x=y=z=0;
Yes = ‘x’;



                         prepared by Taif.A.S.G
Simple programs
 Write C++ Program to find Sum and Average of two
  numbers?

Write C++ Program to find area of a circle?




                    prepared by Taif.A.S.G
C++ statement
                                Control
                              statement
     Selection                     iteration                   jump
     statement                    statement                  statement



If    if-else   switch      for      while   do      break   continue   return


                            prepared by Taif.A.S.G
Decision making
• C++ supports the following statements Known
  as control or decision making statements.
1. if statement.
2. switch statement.
3. Conditional operator ? : statement.




                  prepared by Taif.A.S.G    14
Decision making with if
                statement
The general form of simple if statement is :
                if (<conditional expression>)
                <statement action>

Example:

       if (a > b)
       cout<<"a > b";




                            prepared by Taif.A.S.G   15
Decision making with if
            statement cont..
The general form of simple if else statement is :
                if (<conditional expression>)
                <statement action>
                else
Example:        <statement action>

       if (a > b)
       cout<<" a > b";
       else
       cout<<"a<b";

                            prepared by Taif.A.S.G   16
Decision making with if
            statement cont..
The general form of Multiple if else statement is :
                  if (<conditional expression>)
                  <statement action>
                  else if (<conditional expression>)
                  <statement action>
                  else
Example:          <statement action>
if (a > b)
cout<<" a > b";
 else if (a< b)
 cout<<"b > a";
else
 cout<<" a=b";
                              prepared by Taif.A.S.G   17
Decision making with switch
          statement
• The if statement allows you to select one of
  two sections of code to execute based on a
  boolean value (only two possible values). The
  switch statement allows you to choose from
  many statements.




                    prepared by Taif.A.S.G        18
Decision making with switch
         statement cont..
switch (expr) {
case c1:
statements // do these if expr == c1
 break;
case c2:
statements // do these if expr == c2
 break;
 case c3:
case c4: // Cases can simply fall thru.
statements // do these if expr == any of c's
 break; . . .
default:      // OPTIONAL
statements // do these if expr != any above
 }

                                   prepared by Taif.A.S.G   19
The ? : Operator:
• can be used to replace if...else statements. It has
  the following general form:
  Exp1 ? Exp2 : Exp3;
  Where Exp1, Exp2, and Exp3 are expressions.
• The value of a ? expression is determined like
  this: Exp1 is condition evaluated. If it is true, then
  Exp2 is evaluated and becomes the value of the
  entire ? expression. If Exp1 is false, then Exp3 is
  evaluated and its value becomes the value of the
  expression.
                       prepared by Taif.A.S.G         20
Simple programs
 Write C++ Program to find Number is Positive or
  Negative?

Write C++ Program to find the Grade of student ?

 Write C++ Program to check the day of week by using
  SWITCH-CASE?




                   prepared by Taif.A.S.G
Looping
The C++ language provides three constructs for
  performing loop operations, there are:
   1. The for statement.
   2. The while statement.
   3. The do statement.




                   prepared by Taif.A.S.G        22
Looping cont..
The general form of for statement:

for (initialization; test condition; increment)
 {
    Body of loop
 }


Example:
for( x=0; x<=10; x++)
{
cout<<x;
}                          prepared by Taif.A.S.G   23
Looping cont..
The general form of while statement:
       initialization;
      while(test condition)
     {
    Body of loop
    }

Example:
x=0;
while(x<=10)
{
cout<<x;
x++; }                     prepared by Taif.A.S.G   24
Looping cont..
The general form of do statement:
       initialization;
      do
     {
    Body of loop
    }
   while(test condition);

Example:
x=0;
do
{
cout<<x;
x++; }
while(x<=10) ;            prepared by Taif.A.S.G   25
Int num2        Int num1
                                                             0               0
  Nested Looping                                                             1
for(num2 = 0; num2 <= 3; num2++)                                             2
{                                                                       3 end of loop
   for(num1 = 0; num1 <= 2; num1++)                          1               0
   {                                                                         1
       cout<<num2 << " " <<num1;
                                                                             2
   }
}                                                                       3 end of loop
                                                             2               0
                                                                             1
                                                                             2
                                                                        3 end of loop
                                                             3               0
                                                                             1
                                                                             2
                                                                        3 end of loop
                               prepared by Taif.A.S.G                               26
                                                        4 End of loop
Functions
• A complex problem is often easier to solve by
  dividing it into several smaller
  parts(Modules), each of which can be solved by
  itself. This is called structured programming.
• In C++ Modules Known as Functions & Classes
• main() then uses these functions to solve the
  original problem.


                   prepared by Taif.A.S.G     27
Functions (cont..)
• C++ allows the use of both internal (user-
  defined) and external functions.

• External functions (e.g., abs, ceil, rand,
  sqrt, etc.) are usually grouped into specialized
  libraries (e.g., iostream, stdlib, math,
  etc.)


                     prepared by Taif.A.S.G          28
Function prototype
• The function prototype declares the input and output
  parameters of the function.

• The function prototype has the following syntax:
     <type> <function name>(<type list>);

• Example: A function that returns the absolute value of
  an integer is: int absolute(int);
• If a function definition is placed in front of main(),
  there is no need to include its function prototype.


                       prepared by Taif.A.S.G            29
Function Definition
• A function definition has the following syntax:
  <type> <function name>(<parameter list>){
       <local declarations>
       <sequence of statements>
  }

• For example: Definition of a function that computes the absolute
  value of an integer:

int absolute(int x){
     if (x >= 0) return x;
     else        return -x;
}

• The function definition can be placed anywhere in the program.

                            prepared by Taif.A.S.G                   30
Function call

• A function call has the following syntax:
  <function name>(<argument list>)


  Example: int distance = absolute(-5);




                      prepared by Taif.A.S.G   31

More Related Content

PPTX
Quick sort
PPTX
Conversion of Infix to Prefix and Postfix with Stack
PPTX
Instruction codes
PDF
Control statements
PPTX
Intro to c++
PPTX
Asymptotic Notation
PPTX
C# conditional branching statement
PPT
Data Structures - Searching & sorting
Quick sort
Conversion of Infix to Prefix and Postfix with Stack
Instruction codes
Control statements
Intro to c++
Asymptotic Notation
C# conditional branching statement
Data Structures - Searching & sorting

What's hot (20)

PDF
Java thread life cycle
PPT
Bitwise operators
PPTX
Bubble Sort Algorithm Presentation
PDF
Operators in java
PPTX
Statements and Conditions in PHP
PPTX
Introduction to Selection control structures in C++
PPTX
Graph traversals in Data Structures
PPTX
Design of a two pass assembler
PPTX
Functional Programming
PDF
Decimal adder
PPTX
Complexity analysis - The Big O Notation
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
PPTX
Introduction to programming
PPTX
Deque and its applications
PPT
basic logic gates
PPTX
stack & queue
PDF
Loop invarient
PPT
C++: Constructor, Copy Constructor and Assignment operator
PDF
Lesson 02 python keywords and identifiers
PPTX
A presentation on prim's and kruskal's algorithm
Java thread life cycle
Bitwise operators
Bubble Sort Algorithm Presentation
Operators in java
Statements and Conditions in PHP
Introduction to Selection control structures in C++
Graph traversals in Data Structures
Design of a two pass assembler
Functional Programming
Decimal adder
Complexity analysis - The Big O Notation
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Introduction to programming
Deque and its applications
basic logic gates
stack & queue
Loop invarient
C++: Constructor, Copy Constructor and Assignment operator
Lesson 02 python keywords and identifiers
A presentation on prim's and kruskal's algorithm
Ad

Viewers also liked (20)

PPTX
PDF
C++ programming intro
PPTX
Introduction Of C++
PPT
Introduction to C++
PDF
History of C/C++ Language
PDF
CReVote: un système de vote électronique résistant à la coercition basé sur l...
PPT
CBSE Class XI Programming in C++
PPTX
C vs c++
PDF
Multidimensional arrays in C++
PPTX
Presentation on C++ Programming Language
PPTX
LESS, Le CSS avancé
PPTX
Cs1123 3 c++ overview
PPTX
C vs c++
PPTX
C++ Overview PPT
PPT
Overview of c++
PPTX
Understand Decision structures in c++ (cplusplus)
PPTX
difference between c c++ c#
PDF
Cours php & Mysql - 4éme partie
PPTX
C++ language
PDF
Cours php & Mysql - 5éme partie
C++ programming intro
Introduction Of C++
Introduction to C++
History of C/C++ Language
CReVote: un système de vote électronique résistant à la coercition basé sur l...
CBSE Class XI Programming in C++
C vs c++
Multidimensional arrays in C++
Presentation on C++ Programming Language
LESS, Le CSS avancé
Cs1123 3 c++ overview
C vs c++
C++ Overview PPT
Overview of c++
Understand Decision structures in c++ (cplusplus)
difference between c c++ c#
Cours php & Mysql - 4éme partie
C++ language
Cours php & Mysql - 5éme partie
Ad

Similar to Overview of c++ language (20)

PDF
C++ control structure
DOCX
C++ Loops General Discussion of Loops A loop is a.docx
PPT
FP 201 - Unit 3 Part 2
PPT
Iteration
PPTX
Switch case and looping kim
PDF
[C++][a] tutorial 2
PPT
Control Statement.ppt
PDF
C++ Course - Lesson 1
PPT
for loops in C++ and their functions and applicability
PPT
C++ programming
PPT
C++ programming
PPTX
Computational Physics Cpp Portiiion.pptx
PPTX
Switch case and looping
DOC
Control structures
PPTX
Cs1123 6 loops
PPTX
Switch case and looping new
PPTX
Computer programming
PPTX
lesson 2.pptx
PPTX
LOOPS AND DECISIONS
PPT
Lecture 1
C++ control structure
C++ Loops General Discussion of Loops A loop is a.docx
FP 201 - Unit 3 Part 2
Iteration
Switch case and looping kim
[C++][a] tutorial 2
Control Statement.ppt
C++ Course - Lesson 1
for loops in C++ and their functions and applicability
C++ programming
C++ programming
Computational Physics Cpp Portiiion.pptx
Switch case and looping
Control structures
Cs1123 6 loops
Switch case and looping new
Computer programming
lesson 2.pptx
LOOPS AND DECISIONS
Lecture 1

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
01-Introduction-to-Information-Management.pdf
PDF
Trump Administration's workforce development strategy
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Updated Idioms and Phrasal Verbs in English subject
PPTX
Cell Types and Its function , kingdom of life
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
Lesson notes of climatology university.
PPTX
Cell Structure & Organelles in detailed.
PDF
Complications of Minimal Access Surgery at WLH
PPTX
master seminar digital applications in india
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
STATICS OF THE RIGID BODIES Hibbelers.pdf
History, Philosophy and sociology of education (1).pptx
Computing-Curriculum for Schools in Ghana
LDMMIA Reiki Yoga Finals Review Spring Summer
What if we spent less time fighting change, and more time building what’s rig...
01-Introduction-to-Information-Management.pdf
Trump Administration's workforce development strategy
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Paper A Mock Exam 9_ Attempt review.pdf.
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Updated Idioms and Phrasal Verbs in English subject
Cell Types and Its function , kingdom of life
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Yogi Goddess Pres Conference Studio Updates
Lesson notes of climatology university.
Cell Structure & Organelles in detailed.
Complications of Minimal Access Surgery at WLH
master seminar digital applications in india
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025

Overview of c++ language

  • 1. Overview of C++ language
  • 2. Lecture’s outline What is C++? Identifiers. Constant Semicolons & Blocks in C++ Data type Comments Operator Declaration of variables Giving value to variable C++ statements prepared by Taif.A.S.G
  • 3. What is C++? • Developed by Bjarne Stroustrup (in 1979 at Bell Labs) • C++ is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features. • C++ is a statically typed, compiled, general purpose, case- sensitive, free-form programming language that supports procedural, object-oriented, and generic programming. • C++ is a superset of C that enhancement to the C language and originally named C with Classes but later it was renamed C++. prepared by Taif.A.S.G
  • 4. identifiers They are used for naming classes function, module, variables, object in a program. They follow the following rules: 1) They can have alphabets , digits, and the underscore(_). 2) They must not begin with a digit. 3) Uppercase and lowercase are distinct. 4) They can be of any length. 5) It should not be a keyword. 6) White space is not allowed. prepared by Taif.A.S.G
  • 5. Constant Constant is one whose value cannot be changed after it has been initialized-any attempt to assign to field will produce a compile-error .So, we can declare the constant by using const field and use all uppercase letter. Syntax of declare the constant is: const type name=value Example: const int STRENGTH = 100; const float PI = 3.14; prepared by Taif.A.S.G
  • 6. Semicolons & Blocks in C++: • In C++, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity. • For example: following are two different statements: x = y; y = y+1; prepared by Taif.A.S.G 6
  • 8. Comments C++ can use both the single line comments and multi-line comments . single line comments begin with // and end at the end of line. For longer comments we can create multi-line comments by starting with /* and ending with */ prepared by Taif.A.S.G
  • 9. Operator * / % + - are the mathematical operators * / % have a higher precedence than + or – mathematical operators ++ Increment operator –– Decrement operator == Equal (careful) != Not equal >= Greater than or equal Relational <= Less than or equal operators > Greater than < Less than && logical (sequential) and Logical || logical (sequential) or operators = assignment prepared by Taif.A.S.G
  • 10. Declaration of variables The general form of declaration of variables: Type variable1, variable2,...., variableN; Example: int count; float x,y; double pi; char c1,c2,c3; byte b; prepared by Taif.A.S.G
  • 11. Giving value to variable The general form of giving value to variables: variableName= value; Example: finalValue=100; x=y=z=0; Yes = ‘x’; prepared by Taif.A.S.G
  • 12. Simple programs  Write C++ Program to find Sum and Average of two numbers? Write C++ Program to find area of a circle? prepared by Taif.A.S.G
  • 13. C++ statement Control statement Selection iteration jump statement statement statement If if-else switch for while do break continue return prepared by Taif.A.S.G
  • 14. Decision making • C++ supports the following statements Known as control or decision making statements. 1. if statement. 2. switch statement. 3. Conditional operator ? : statement. prepared by Taif.A.S.G 14
  • 15. Decision making with if statement The general form of simple if statement is : if (<conditional expression>) <statement action> Example: if (a > b) cout<<"a > b"; prepared by Taif.A.S.G 15
  • 16. Decision making with if statement cont.. The general form of simple if else statement is : if (<conditional expression>) <statement action> else Example: <statement action> if (a > b) cout<<" a > b"; else cout<<"a<b"; prepared by Taif.A.S.G 16
  • 17. Decision making with if statement cont.. The general form of Multiple if else statement is : if (<conditional expression>) <statement action> else if (<conditional expression>) <statement action> else Example: <statement action> if (a > b) cout<<" a > b"; else if (a< b) cout<<"b > a"; else cout<<" a=b"; prepared by Taif.A.S.G 17
  • 18. Decision making with switch statement • The if statement allows you to select one of two sections of code to execute based on a boolean value (only two possible values). The switch statement allows you to choose from many statements. prepared by Taif.A.S.G 18
  • 19. Decision making with switch statement cont.. switch (expr) { case c1: statements // do these if expr == c1 break; case c2: statements // do these if expr == c2 break; case c3: case c4: // Cases can simply fall thru. statements // do these if expr == any of c's break; . . . default: // OPTIONAL statements // do these if expr != any above } prepared by Taif.A.S.G 19
  • 20. The ? : Operator: • can be used to replace if...else statements. It has the following general form: Exp1 ? Exp2 : Exp3; Where Exp1, Exp2, and Exp3 are expressions. • The value of a ? expression is determined like this: Exp1 is condition evaluated. If it is true, then Exp2 is evaluated and becomes the value of the entire ? expression. If Exp1 is false, then Exp3 is evaluated and its value becomes the value of the expression. prepared by Taif.A.S.G 20
  • 21. Simple programs  Write C++ Program to find Number is Positive or Negative? Write C++ Program to find the Grade of student ?  Write C++ Program to check the day of week by using SWITCH-CASE? prepared by Taif.A.S.G
  • 22. Looping The C++ language provides three constructs for performing loop operations, there are: 1. The for statement. 2. The while statement. 3. The do statement. prepared by Taif.A.S.G 22
  • 23. Looping cont.. The general form of for statement: for (initialization; test condition; increment) { Body of loop } Example: for( x=0; x<=10; x++) { cout<<x; } prepared by Taif.A.S.G 23
  • 24. Looping cont.. The general form of while statement: initialization; while(test condition) { Body of loop } Example: x=0; while(x<=10) { cout<<x; x++; } prepared by Taif.A.S.G 24
  • 25. Looping cont.. The general form of do statement: initialization; do { Body of loop } while(test condition); Example: x=0; do { cout<<x; x++; } while(x<=10) ; prepared by Taif.A.S.G 25
  • 26. Int num2 Int num1 0 0 Nested Looping 1 for(num2 = 0; num2 <= 3; num2++) 2 { 3 end of loop for(num1 = 0; num1 <= 2; num1++) 1 0 { 1 cout<<num2 << " " <<num1; 2 } } 3 end of loop 2 0 1 2 3 end of loop 3 0 1 2 3 end of loop prepared by Taif.A.S.G 26 4 End of loop
  • 27. Functions • A complex problem is often easier to solve by dividing it into several smaller parts(Modules), each of which can be solved by itself. This is called structured programming. • In C++ Modules Known as Functions & Classes • main() then uses these functions to solve the original problem. prepared by Taif.A.S.G 27
  • 28. Functions (cont..) • C++ allows the use of both internal (user- defined) and external functions. • External functions (e.g., abs, ceil, rand, sqrt, etc.) are usually grouped into specialized libraries (e.g., iostream, stdlib, math, etc.) prepared by Taif.A.S.G 28
  • 29. Function prototype • The function prototype declares the input and output parameters of the function. • The function prototype has the following syntax: <type> <function name>(<type list>); • Example: A function that returns the absolute value of an integer is: int absolute(int); • If a function definition is placed in front of main(), there is no need to include its function prototype. prepared by Taif.A.S.G 29
  • 30. Function Definition • A function definition has the following syntax: <type> <function name>(<parameter list>){ <local declarations> <sequence of statements> } • For example: Definition of a function that computes the absolute value of an integer: int absolute(int x){ if (x >= 0) return x; else return -x; } • The function definition can be placed anywhere in the program. prepared by Taif.A.S.G 30
  • 31. Function call • A function call has the following syntax: <function name>(<argument list>) Example: int distance = absolute(-5); prepared by Taif.A.S.G 31