C++ Examples
- Write a C++ Program to print a welcome text in a separate line.
- Write a Program in C++ to add two numbers.
- C++ program for addition of two numbers using functions.
- Add two numbers in C++ using class.
- Addition of two numbers using call by reference in C++
- C++ program to write a program to add two numbers using call by value.
- Swapping of two numbers in C++ without using third variable.
- Swap two numbers in C++ using function.
- C++ program to swap two numbers using class.
- C++ program to swap two numbers using call by value.
- C++ program to swap two numbers using pointers.
- Write a program to swap private data members of two classes using friend function.
- write a program to add data objects of two different classes using friend function.
- Threading in C++.
- C++ thread lambda
- C++ thread lambda with parameter
- C++ thread lambda pass by reference
- Singleton C++ example
Swapping of two numbers in C++ without using third variable.
#include <iostream>
using namespace std;
int main()
{
//Variable declaration
int number1,number2;
cout<<"Enter your first number to swap ";
cin>>number1;
cout<<"Enter your second number to swap ";
cin>>number2;
cout<<"Before swaping the numbers are "<<number1<<" and "<<number2<<endl;
// swaping of Variable using airthmetic operators
number1 = number1 + number2;
number2 = number1 - number2;
number1 = number1 - number2;
cout<<"After swaping the numbers are "<<number1<<" and "<<number2<<endl;
return 0;
} Output
Enter your first number to swap 4
Enter your second number to swap 6
Before swaping the numbers are 4 and 6
After swaping the numbers are 6 and 4