Skip to main content

Featured

C++ Program to Perform Linear Search on a Vector

  C++ Program to Perform Linear Search on a Vector Introduction In this C++ program, we will learn how to perform a Linear Search on a vector. The program first takes the size of the vector and its elements as input. Then it asks the user for the element to search. If the element is found, it displays the index where it is located. Otherwise, it displays a message indicating that the element is not found. C++ Program #include<bits/stdc++.h> using namespace std; int main() { int num, search, found = 0; cout << "Enter the size of the vector:" << endl; cin >> num; vector<int> v(num); cout << "Enter " << num << " elements in vector:" << endl; for(int i = 0; i < num; i++) { cin >> v[i]; } cout << "Enter element that you want to search:" << endl; cin >> search; for(int i = 0; i < num; i++) { ...

C++ Program Using Inline Function (Square / Multiplication)

C++ Inline Function Example – Square Using Inline Function

C++ Program Using Inline Function (Square / Multiplication)


#include <iostream>
using namespace std;

inline int squar(int a, int b)
{
    return a * b;
}

int main()
{
    int x, y;
    cout << "Enter any two numbers:" << endl;
    cin >> x >> y;
    cout << "the squar of " << x << " and " << y
         << " is " << squar(x, y) << endl;
    return 0;
}
  

๐Ÿ“˜ Explanation:

This program demonstrates the use of an inline function in C++ to perform multiplication of two numbers.

The function squar() is declared using the inline keyword. When this function is called, the compiler attempts to replace the function call with the actual function code to reduce function call overhead.

Inline functions are best suited for small and frequently used functions, as they improve execution speed by avoiding repeated function calls.

๐Ÿงพ Sample Output:

Enter any two numbers:
4 5
the squar of 4 and 5 is 20
  

๐Ÿ”‘ Keywords:

C++ inline function, inline multiplication, C++ square program, inline function example, C++ basics, function optimization

๐Ÿ” Search Description:

Learn how inline functions work in C++ with a simple program that multiplies two numbers. Includes explanation, syntax, and example output.

๐Ÿ“Œ Hashtags:

#CPlusPlus #InlineFunction #CPPBasics #Programming #Coding #1printf

Comments

Popular Posts

๐ŸŒ™