First of all, according to the C standard, the main function without parameters must be declared as
int main( void )
Since the program uses the standard ptintf function, it is required to include the header <stdio.h> , where this function is declared.
#include <stdio.h>
In this declaration, the postfix expression signfx() is used as the initializer:
int x1=signfx();
However, the name signfx is undefined. Older compilers or newer compilers that support compatibility with older compilers can compile this code, because before the current standard was adopted, the compiler assumed by default that this is a function name that has the return type int
However, now it does not conform to the C standard, and therefore compilers may mark this sentence as erroneous. You must first declare this name as a function name before using it in a program. for example
int signfx( void ); ^^^^^
Notice that the Void keyword is used as a parameter. This means that the function has no parameters.
These two announcements, unlike the C ++ programming language
int signfx( void ); int signfx();
semantically different. The first declaration says that the function has no parameters, and the second declaration says that nothing is known about the parameters of the function, and the number and types of parameters will be derived from calling this function in the program.
With that said, your program will look like this.
#include <stdio.h> int signfx( void ); int main(void) { int x1 = signfx(); printf( "x1 = %d\n", x1 ); return 0; } int signfx( void ) { int x = 20; return x; }
Its output to the console
x1 = 20
You could declare and define a function immediately before using it by placing its definition before the main function. The definition of a function is also its declaration. for example
#include <stdio.h> int signfx( void ) { int x = 20; return x; } int main(void) { int x1 = signfx(); printf( "x1 = %d\n", x1 ); return 0; }
Keep in mind that the concept method refers to classes, that is, classes and class objects have methods. Since there are no classes in C, there is no such term as a method, but the term function is used.