UrbanPro
true

Learn Programming Languages from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

C, C++, JAVA Tutor

Sumit Singh
24/07/2018 0 0

* Program to swap two numbers using a temporary variable with each statement explained with comments *

 

#include                // headerfile for cout statement
using namespace std;              // include standard library files

int main()                        // main()- starting point of the program with int return type  
{                                 //  start of main()
    int a = 5, b = 10, temp;      // 3 variables where a,b are initialised and a temp variable 

    cout << "Before swapping." << endl;               // print statement
    cout << "a = " << a << ", b = " << b << endl;     // values before swapping

    temp = a;                     // assign a to temp
    a = b;                        // assign b to a
    b = temp;                     // final step in  swapping with assigning temp ,ie, a to b

    cout << "\nAfter swapping." << endl;              // print statement
    cout << "a = " << a << ", b = " << b << endl;     // values after swapping

    return 0;                     //return value required coz on int return type of main()
}                                 // termination of main()

// Semi-colon ';' is termination of each valid C++ statement

 

0 Dislike
Follow 2

Please Enter a comment

Submit

Other Lessons for You

Do You Know Size Of Empty Class and Reason?
Size of empty class is always 1 byte. Reason is, in order to differentiate one object to another object, the size of empty class is always 1 byte. See the below c++ code snippet. Here there are three...

FUNDAMENTALS OF COMPUTER ALGORITHMS
INTRODUCTION: The word algorithm is named after the ninth century scholar 'Abu Jafar Muhammad Ibn Musa Al-Khwarizmi'. An algorithm is a step-by-step procedure by which a computer can produce the required...
M

Mukesh Tekwani

2 0
0

STORAGE CLASSES
A storage class defines the scope (visibility) and life-time of variables and/or functions within a C Program. They precede the type that they modify. We have four different storage classes in a C program: auto register static extern ...

Be A Python Dev
Currently, in the programming world, Python is one of the languages with a high rising demand profile. And this article will explain why that isn’t slowing down in the foreseeable future.Python...

History Of Programming Languages
1800: Joseph Marie Jacquard teaches a loom to read punch cards, creating the first heavily multi-threaded processing unit. His invention was fiercely opposed by the silk-weavers who expected the birth...
X

Looking for Programming Languages Classes?

The best tutors for Programming Languages Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Programming Languages with the Best Tutors

The best Tutors for Programming Languages Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more