Skip to main content

Posts

Showing posts with the label inline function

What is inline function? Using inline function, write a program to add two integers and returns sum.

 An inline function is a function that is expanded in line at the point where it is called. It is a function that is defined with the 'inline' keyword, which indicates to the compiler that the function should be expanded inline, rather than called as a separate function. The inline function can provide faster execution than a regular function call because there is no function call overhead. Here is an example program that uses an inline function to add integers and return the sum: #include <iostream> using namespace std; inline int add(int a, int b) {     return a + b; } int main() {     int x = 30;     int y = 40;     int result = add(x, y);     cout << "The sum of " << x << " and " << y << " is " << result << endl;     return 0; } In the above program the "add()" function is defined with the "inline" keyword, which tells the compiler to expand the function in line wherever ...