Ayesha Gupta
Ayesha Gupta

Reputation: 145

Calling the same function within the function

#include<stdio.h>
int slogan();
int main()
{
    slogan(slogan());
    return 0;
}
int slogan()
{
    printf("onlyme\n");
}

My doubt is, the slogan function has no argument list in its prototype, then how come it accepts the function call as its argument?

Upvotes: 3

Views: 133

Answers (3)

YonBruchim
YonBruchim

Reputation: 101

Look at First answer here(and second) The first answer will give you an Accurate explanation of a functions declaration

Section 6.11.6 Function declarators(K&R C)

The use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature.

Upvotes: 0

Fred Foo
Fred Foo

Reputation: 363487

Because in C,

int slogan();

declares a function without saying anything about its arguments. This is not a prototype declaration at all, it's an old-style K&R declaration. The prototype declaration for a function taking to arguments is

int slogan(void);

The former form exists for backward compability with pre-1989 C, when you couldn't provide argument information in the prototype at all.

Upvotes: 6

Nikos Athanasiou
Nikos Athanasiou

Reputation: 31489

In c the empty parameter list does not mean function that takes no arguments. It means function with unspecified number of arguments

To declare a function that takes no arguments write :

int func(void);

Upvotes: 8

Related Questions