C Functions | AsgarTech



C Functions

In C programming, there are several types of functions that can be used depending on the specific task that needs to be performed. Here are some common types of functions in C

These are types of function in c programming

  • Void Functions: A void function is a function that does not return a value. These functions are typically used for tasks that do not require a return value, such as printing output to the console or modifying a global variable.

  • Functions with Return Values: A function with a return value is a function that calculates and returns a value. These functions are often used for calculations or data processing tasks.

  • Functions with Parameters: A function with parameters is a function that takes one or more input values, called parameters, and uses them in its calculation or processing.

  • Recursive Functions: A recursive function is a function that calls itself repeatedly until a specific condition is met. These functions are often used for tasks that involve repeatedly breaking a problem down into smaller sub-problems.

  • Inline Functions: An inline function is a function that is expanded by the compiler at the point where it is called, rather than being executed as a separate function call. Inline functions can provide performance benefits for small, frequently-called functions.

  • Library Functions: Library functions are pre-written functions that are included in standard libraries, such as the math library or string library. These functions can be used by a programmer without having to write the function code themselves.

Now these are  Function With Example:-

Void Functions: 

A void function is a function that does not return a value. These functions are typically used for tasks that do not require a return value, such as printing output to the console or modifying a global variable. Here's an example:

void greet() {
    printf("Hello, world!\n");
}

Functions with Return Values: 

A function with a return value is a function that calculates and returns a value. These functions are often used for calculations or data processing tasks. Here's an example:

int square(int num) {
    int result = num * num;
    return result;
}

Functions with Parameters:

A function with parameters is a function that takes one or more input values, called parameters, and uses them in its calculation or processing. Here's an example:

int factorial(int num) {
    if (num == 1) {
        return 1;
    } else {
        return num * factorial(num - 1);
    }
}

Inline Functions: 

An inline function is a function that is expanded by the compiler at the point where it is called, rather than being executed as a separate function call. Inline functions can provide performance benefits for small, frequently-called functions. Here's an example:

inline int square(int num) {
    return num * num;
}

These are some of the most common types of functions in C programming, but there are many other types and variations depending on the specific task and programming style.


Study material Check These👇👇

Top HTML and HTML5 Interview Questions For Fresher- AsgarTech

Thanks 



No comments: