Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

C++ Program to Swap Two Numbers Using Inline Function

C++ Inline Function – Swap Two Numbers

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

πŸŒ™