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
Comments
Post a Comment