w3resource

C Programming Exercises, Practice, Solution : Inline Function

C Inline function [11 Exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

inline function:

From ibm.com -
An inline function is one for which the compiler copies the code from the function definition directly into the code of the calling function rather than creating a separate set of instructions in memory. Instead of transferring control to and from the function code segment, a modified copy of the function body may be substituted directly for the function call. In this way, the performance overhead of a function call is avoided. Using the inline specifier is only a suggestion to the compiler that an inline expansion can be performed; the compiler is free to ignore the suggestion.

C - Any function, with the exception of main, can be declared or defined as inline with the inline function specifier. Static local variables are not allowed to be defined within the body of an inline function.

The following code fragment shows an inline function definition:

inline int add(int i, int j) { return i + j; }

1. Write a C program to compute the area of a circle given its radius using inline functions.
Expected Output:

The area of the circle (radius = 5.000000) is 78.539816
The area of the circle (radius = 12.000000) is 452.389342

Click me to see the solution

2. Write a C program to compute absolute difference between two integers using inline functions.
Expected Output:

Absolute difference between 100 and 200 is 100

Absolute difference between 200 and 100 is 100

Click me to see the solution

3. Write a C program to compute the minimum of two integers using inline function.
Expected Output:

Minimum of 110 and 120 is 110
Minimum of -110 and -120 is -120

Click me to see the solution

4. Write a C program to compute the maximum of two integers using inline function.
Expected Output:

Maximum of 110 and 120 is 120
Maximum of -110 and -120 is -110

Click me to see the solution

5. Write a C program to compute the length of a given string using inline function.
Expected Output:

The length of the string 'w3resource.com' is 14

The length of the string 'Learn C Programming' is 19

Click me to see the solution

6. Write a C program to convert a temperature from Celsius to Fahrenheit and vice versa using an inline function.
Expected Output:

32.00 Celsius is equal to 89.60 Fahrenheit

89.60 Fahrenheit is equal to 32.00 Celsius

Click me to see the solution

7. Write a C program to count the number of vowels in a given string using an inline function.
Expected Output:

The string "w3resource.com" contains 5 vowels.

The string "United States of America " contains 10 vowels.

Click me to see the solution

8. Write a C program to check if a given integer is prime using an inline function.
Expected Output:

Input a positive integer: 13
13 is a prime number.
Input a positive integer: 18
18 is not a prime number.

Click me to see the solution

9. Write a C program to check if a given integer is even or odd using an inline function.
Expected Output:

Input an integer: 3
3 is odd.
Input an integer: 46
46 is even.

Click me to see the solution

10. Write a C program to reverse a given string using an inline function.
Expected Output:

Input a string: Wikipedia
Before reverse: Wikipedia
After reverse: aidepikiW

Input a string: C language
Before reverse: C language
After reverse: egaugnal C

Click me to see the solution

11. Write a C program to compute the sum of a variable number of integers passed as arguments using an inline function.
Expected Output:

Input a string: Wikipedia
Before reverse: Wikipedia
After reverse: aidepikiW

Input a string: C language
Before reverse: C language
After reverse: egaugnal C

Click me to see the solution

C Programming Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/c-programming-exercises/inline_function/index.php