We need to declare function prototype for user defined functions in C. Function prototype provides the following information about the function to the compiler.
1. Return type
2. Function name
3. Argument list
Example:
int add(int, int);
<return type> <function_name> (<arg1>, <arg2>,..);
Example C program to illustrate function prototype:
#include <stdio.h>
void print_info(char []);
/*
* void print_info(char []) is the function
* prototype with return type "void", func
* name "print_info" and argument "a char
* array"
*/
int main() {
char str[100];
printf("Enter your input string:");
fgets(str, 100, stdin);
print_info(str);
return 0;
}
void print_info(char array[]) {
printf("%s", array);
}
Output:
jp@jp-VirtualBox:~/cpgms/functions$ ./a.out
Enter your input string: Helloworld
Helloworld
Enter your input string: Helloworld
Helloworld
No comments:
Post a Comment