The following are the various function prototypes available in C:
1. Function with no arguments and no return value.
2. Function with arguments and no return value.
3. Function with arguments and return value.
4. Function with arguments and no return value.
Example C program to illustrate various function prototypes:
#include <stdio.h>
void noarg_noret();
void arg_noret(int);
int arg_ret(int);
int noarg_ret();
int main() {
int a, ret;
printf("Enter a value :");
scanf("%d", &a);
noarg_noret();
arg_noret(a);
ret = arg_ret(a);
printf("Return value of arg_ret():%d\n\n", ret);
ret = noarg_ret();
printf("Return value of noarg_ret():%d\n", ret);
return 0;
}
/* function with no argument and no return value */
void noarg_noret() {
printf("Inside noarg_noret():\n");
printf("Function with no argument and return value\n\n");
}
/* function with argument and no return value */
void arg_noret(int val) {
printf("Inside arg_noret():\n");
printf("Argument value: %d\n", val);
printf("Function with argument and no return value\n\n");
}
/* function with argument and return value */
int arg_ret(int val) {
printf("Inside arg_ret():\n");
printf("Argument value:%d\n", val);
printf("Function with argument and return value\n");
return (val + 10);
}
/* function with no argument and with return value */
int noarg_ret() {
printf("Inside noarg_ret():\n");
printf("Function with no argument and with return value\n");
return 0;
}
Output:
jp@jp-VirtualBox:~/cpgms/functions$ ./a.out
Enter a value :90
Enter a value :90
Inside noarg_noret():
Function with no argument and return value
Inside arg_noret():
Argument value: 90
Function with argument and no return value
Inside arg_ret():
Argument value:90
Function with argument and return value
Return value of arg_ret():100
Inside noarg_ret():
Function with no argument and with return value
Return value of noarg_ret():0
Function with no argument and return value
Inside arg_noret():
Argument value: 90
Function with argument and no return value
Inside arg_ret():
Argument value:90
Function with argument and return value
Return value of arg_ret():100
Inside noarg_ret():
Function with no argument and with return value
Return value of noarg_ret():0
No comments:
Post a Comment