Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C++ Program to Swap Two Numbers Using Inline Function
C++ Program to Swap Two Numbers Using Inline Function
#include <iostream>
using namespace std;
inline void swapNum(int &a, int &b)
{
int temp = a;
a = b;
b = temp;
}
int main()
{
int x, y;
cout << "Enter two numbers: ";
cin >> x >> y;
swapNum(x, y);
cout << "After swapping:\n";
cout << "x = " << x << " y = " << y;
return 0;
}
๐ Explanation:
This program demonstrates swapping of two numbers in C++ using an inline function and call by reference.
The function swapNum() is declared as an inline function and
takes two parameters by reference. This allows the function to directly
modify the original values of the variables.
Using call by reference avoids creating copies of variables and ensures
that the swapped values are reflected in the main() function.
๐งพ Sample Output:
Enter two numbers: 10 20 After swapping: x = 20 y = 10
๐ Keywords:
C++ inline function, swap two numbers in C++, call by reference, inline swap function, C++ basics
๐ Search Description:
Learn how to swap two numbers in C++ using an inline function and call by reference. This program includes explanation, syntax, and output.
๐ Hashtags:
#CPlusPlus #InlineFunction #CallByReference #SwapNumbers #CPPBasics #1printf
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment