Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Tuesday, September 27, 2022

Example of user define function with no argument and no return value in C Programming

 An example of user define function with no argument and no return value in C programming.


An example of user define function with no argument and no return value in C programming.


Introduction:

In C programming, functions are a powerful tool for breaking down large programs into smaller, more manageable pieces. They allow us to modularize our code, making it easier to read, maintain, and reuse. User-defined functions are functions that are created by the programmer, and they can be customized to perform a specific task. In this article, we will discuss an example of a user-defined function with no argument and no return value.

A user-defined function is a function that the programmer creates to perform a specific task. In C programming, we define a function using the following syntax:

return_type function_name(parameters) {
    // function body
}

  • The return_type specifies the data type of the value that the function returns.
  • The function_name is the name of the function.
  • The parameters are the values that the function takes as input.

In our example, we will create a user-defined function with no argument and no return value. This means that the function will not take any input, and it will not return any value.

Example:

#include <stdio.h>
void display_message() {
    printf("Hello, world!\n");
}

int main() {
    display_message(); // calling the function
    return 0;
}

In this example, we have defined a user-defined function called print_hello_world(). This function takes no arguments and does not return any value. It simply prints the message "Hello, World!" to the console using the printf() function.

In the main() function, we are calling the print_hello_world() function, which executes the function's body and prints the message to the console.

Conclusion:

To summarize, the user-defined function with no argument and no return value that we have created simply prints a message to the console. This may seem like a trivial example, but it demonstrates the basic syntax and structure of a user-defined function. By using functions, we can break down our code into smaller, more manageable pieces, making it easier to write, read, and maintain.


You can also Read:





No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages