Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

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

Popular Posts

πŸŒ™