30/09/2018, 19:08

Puzzle: Can we call an undeclared function in C?

Let see the code below.

#include <stdio.h>

int main(void) {
    // your code goes here
    printf("%d
", func());
    return 0;
}

int func()    {
    return 10;
}

Can we run this code and get no error?

while (!(sucesecd = try())) viết 21:11 ngày 30/09/2018

I think we can do that by declare a prototype of 'func ’ before main function like this:

int func();

is it solution?

*grab popcorn* viết 21:24 ngày 30/09/2018

First seen, No f way :))
After compiled: ⊙_⊙ Wot? How?

... viết 21:12 ngày 30/09/2018

This topic sholve this issue.

GeeksforGeeks – 5 Aug 10

Can we call an undeclared function in C++? - GeeksforGeeks

Calling an undeclared function is poor style in C (See this) and illegal in C++. So is passing arguments to a function using a declaration… Read More »

Conclusion:
In C, we can call an undeclared function, but we can’t do this in C++.

*grab popcorn* viết 21:22 ngày 30/09/2018

while (!(sucesecd = try())) viết 21:19 ngày 30/09/2018

OMG, how stupid i’m

... viết 21:20 ngày 30/09/2018

Your answer is true. This is just a trick in C. Don’t worry about that.
I am the same you before found this issue.

Bài liên quan
0