SlideShare a Scribd company logo
C++ Programm
• / operating with variables
• #include using namespace
• std; int main ()
• { // declaring variables:
• int a, b; int result; // process: a = 5; b = 2; a =
a + 1; result = a - b; // print out the result:
cout << result; // terminate the program:
return 0; }
C++
• // initialization of variables #include using
namespace std; int main () { int a=5; // initial
value = 5 int b(2); // initial value = 2 int result;
// initial value undetermined a = a + 3; result =
a - b; cout << result; return 0; }
• / compound assignment operators #include
using namespace std; int main () { int a, b=3; a
= b; a+=2; // equivalent to a=a+2 cout << a;
return 0; }
• // goto loop example #include using
namespace std; int main () { int n=10; loop:
cout << n << ", "; n--; if (n>0) goto loop; cout
<< "FIRE!n"; return 0; }
• // function example #include using
namespace std; int addition (int a, int b) { int r;
r=a+b; return (r); } int main () { int z; z =
addition (5,3); cout << "The result is " << z;
return 0; }
• // function example #include using
namespace std; int subtraction (int a, int b) {
int r; r=a-b; return (r); } int main () { int x=5,
y=3, z; z = subtraction (7,2); cout << "The first
result is " << z << 'n'; cout << "The second
result is " << subtraction (7,2) << 'n'; cout <<
"The third result is " << subtraction (x,y) <<
'n'; z= 4 + subtraction (x,y); cout << "The
fourth result is " << z << 'n'; return 0; }
• // passing parameters by reference #include
using namespace std; void duplicate (int& a,
int& b, int& c) { a*=2; b*=2; c*=2; } int main ()
{ int x=1, y=3, z=7; duplicate (x, y, z); cout <<
"x=" << x << ", y=" << y << ", z=" << z; return 0;
}
• // more than one returning value #include
using namespace std; void prevnext (int x,
int& prev, int& next) { prev = x-1; next = x+1; }
int main () { int x=100, y, z; prevnext (x, y, z);
cout << "Previous=" << y << ", Next=" << z;
return 0; }
• // default values in functions #include using
namespace std; int divide (int a, int b=2) { int
r; r=a/b; return (r); } int main () { cout <<
divide (12); cout << endl; cout << divide (20,4);
return 0; }

More Related Content

PPT
Chapter2
PDF
C++ Nested loops, matrix and fuctions.pdf
PPTX
Programming Fundamentals
PPT
Lecture#6 functions in c++
PPTX
C++_Functions_Presentation of CS eve.pptx
PPT
C++ programming
PPTX
Intro to C++
PPTX
Object oriented programming system with C++
Chapter2
C++ Nested loops, matrix and fuctions.pdf
Programming Fundamentals
Lecture#6 functions in c++
C++_Functions_Presentation of CS eve.pptx
C++ programming
Intro to C++
Object oriented programming system with C++

Similar to C++ Programm.pptx (20)

PPT
Savitch ch 02
PDF
Cs211 module 1_2015
PDF
Cs211 module 1_2015
PPT
PPTX
Introduction to C++ lecture ************
PPT
Pengaturcaraan asas
PPTX
Programming fundamental 02.pptx
PPTX
C++ Overview PPT
PPTX
cppt-170218053903.pptxhjkjhjjjjjjjjjjjjjjj
PPT
02a fundamental c++ types, arithmetic
PDF
C++ Course - Lesson 2
PPT
C++ basics
PPTX
c++ introduction, array, pointers included.pptx
PPTX
Amit user defined functions xi (2)
PPT
Savitch Ch 02
PPT
Savitch Ch 02
PPTX
Understanding Basic C++ Program for Arithmetic Operations.pptx
PPTX
POLITEKNIK MALAYSIA
Savitch ch 02
Cs211 module 1_2015
Cs211 module 1_2015
Introduction to C++ lecture ************
Pengaturcaraan asas
Programming fundamental 02.pptx
C++ Overview PPT
cppt-170218053903.pptxhjkjhjjjjjjjjjjjjjjj
02a fundamental c++ types, arithmetic
C++ Course - Lesson 2
C++ basics
c++ introduction, array, pointers included.pptx
Amit user defined functions xi (2)
Savitch Ch 02
Savitch Ch 02
Understanding Basic C++ Program for Arithmetic Operations.pptx
POLITEKNIK MALAYSIA
Ad

More from Åįjâž Ali (19)

PPTX
Ecosystem Services | Equatic system service
PDF
Foundation Types of Foundation Sheetpile
PDF
1. Intro-Engineering Projects-Building-Orientation and Ventilation....pdf
PDF
pakistanresolution-1940-140311235028-phpapp01-180517192527.pdf
PDF
chapter1-tawheed-190930114224.pdf
PDF
quran-1234139943307346-2.pdf
PPTX
Lecture 01-2 (Functions).pptx
PDF
twonation21-210728115429.pdf
PDF
formationofallindiamuslimleague-150411092052-conversion-gate01.pdf
PPTX
ED-Lecture-8.pptx
PPTX
Lecture 1.pptx
PPT
soorah hujrat
PPT
what is zakat
PDF
shah waliullah.pdf
PDF
fatehmakkah-thegreatvictory-150328021805-conversion-gate01.pdf
PDF
Islamic ethics
PDF
compilation of quran
PPTX
GEO PRESENTATION.pptx
PDF
ARMS RACE IN SOUTH ASIA
Ecosystem Services | Equatic system service
Foundation Types of Foundation Sheetpile
1. Intro-Engineering Projects-Building-Orientation and Ventilation....pdf
pakistanresolution-1940-140311235028-phpapp01-180517192527.pdf
chapter1-tawheed-190930114224.pdf
quran-1234139943307346-2.pdf
Lecture 01-2 (Functions).pptx
twonation21-210728115429.pdf
formationofallindiamuslimleague-150411092052-conversion-gate01.pdf
ED-Lecture-8.pptx
Lecture 1.pptx
soorah hujrat
what is zakat
shah waliullah.pdf
fatehmakkah-thegreatvictory-150328021805-conversion-gate01.pdf
Islamic ethics
compilation of quran
GEO PRESENTATION.pptx
ARMS RACE IN SOUTH ASIA
Ad

Recently uploaded (20)

PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
01-Introduction-to-Information-Management.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
Pharma ospi slides which help in ospi learning
PDF
Complications of Minimal Access Surgery at WLH
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Lesson notes of climatology university.
PDF
Computing-Curriculum for Schools in Ghana
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
GDM (1) (1).pptx small presentation for students
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
Module 4: Burden of Disease Tutorial Slides S2 2025
01-Introduction-to-Information-Management.pdf
Anesthesia in Laparoscopic Surgery in India
Abdominal Access Techniques with Prof. Dr. R K Mishra
TR - Agricultural Crops Production NC III.pdf
Insiders guide to clinical Medicine.pdf
Institutional Correction lecture only . . .
Pharma ospi slides which help in ospi learning
Complications of Minimal Access Surgery at WLH
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Basic Mud Logging Guide for educational purpose
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Lesson notes of climatology university.
Computing-Curriculum for Schools in Ghana
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Renaissance Architecture: A Journey from Faith to Humanism
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
GDM (1) (1).pptx small presentation for students
STATICS OF THE RIGID BODIES Hibbelers.pdf
O7-L3 Supply Chain Operations - ICLT Program

C++ Programm.pptx

  • 1. C++ Programm • / operating with variables • #include using namespace • std; int main () • { // declaring variables: • int a, b; int result; // process: a = 5; b = 2; a = a + 1; result = a - b; // print out the result: cout << result; // terminate the program: return 0; }
  • 2. C++ • // initialization of variables #include using namespace std; int main () { int a=5; // initial value = 5 int b(2); // initial value = 2 int result; // initial value undetermined a = a + 3; result = a - b; cout << result; return 0; }
  • 3. • / compound assignment operators #include using namespace std; int main () { int a, b=3; a = b; a+=2; // equivalent to a=a+2 cout << a; return 0; }
  • 4. • // goto loop example #include using namespace std; int main () { int n=10; loop: cout << n << ", "; n--; if (n>0) goto loop; cout << "FIRE!n"; return 0; }
  • 5. • // function example #include using namespace std; int addition (int a, int b) { int r; r=a+b; return (r); } int main () { int z; z = addition (5,3); cout << "The result is " << z; return 0; }
  • 6. • // function example #include using namespace std; int subtraction (int a, int b) { int r; r=a-b; return (r); } int main () { int x=5, y=3, z; z = subtraction (7,2); cout << "The first result is " << z << 'n'; cout << "The second result is " << subtraction (7,2) << 'n'; cout << "The third result is " << subtraction (x,y) << 'n'; z= 4 + subtraction (x,y); cout << "The fourth result is " << z << 'n'; return 0; }
  • 7. • // passing parameters by reference #include using namespace std; void duplicate (int& a, int& b, int& c) { a*=2; b*=2; c*=2; } int main () { int x=1, y=3, z=7; duplicate (x, y, z); cout << "x=" << x << ", y=" << y << ", z=" << z; return 0; }
  • 8. • // more than one returning value #include using namespace std; void prevnext (int x, int& prev, int& next) { prev = x-1; next = x+1; } int main () { int x=100, y, z; prevnext (x, y, z); cout << "Previous=" << y << ", Next=" << z; return 0; }
  • 9. • // default values in functions #include using namespace std; int divide (int a, int b=2) { int r; r=a/b; return (r); } int main () { cout << divide (12); cout << endl; cout << divide (20,4); return 0; }