Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "implicit declaration of function" mean?

Tags:

#include <stdio.h>

int main()
{
    int a = 4;
    int b = 3;
    addNumbers(a, b);
}

int addNumbers(int a, int b)
{
    return a + b;
}

Why does this not compile, I get a message saying implicit declaration of function addNumbers()?

like image 614
bob Avatar asked Jan 29 '10 10:01

bob


People also ask

What is an implicit declaration of a function?

If a name appears in a program and is not explicitly declared, it is implicitly declared. The scope of an implicit declaration is determined as if the name were declared in a DECLARE statement immediately following the PROCEDURE statement of the external procedure in which the name is used.

What is implicit declaration of function warning in C?

Implicit declaration of functions is not allowed; every function must be explicitly declared before it can be called. In C90, if a function is called without an explicit prototype, the compiler provides an implicit declaration.

What is implicit declaration of function error in C with example?

-Werror-implicit-function-declaration Give a warning (or error) whenever a function is used before being declared. The form -Wno-error-implicit-function-declaration is not supported. This warning is enabled by -Wall (as a warning, not an error).

What is implicit variable declaration?

Implicit variable declaration means the type of the variable is assumed by the operators, but any data can be put in it. In C, int x = 5; printf(x-5); x = "test"; printf(x-5); returns a compile time error when you set x to test.


1 Answers

Either define the function before main() or provide its prototype before main().

So either do this:

#include <stdio.h>

int addNumbers(int a, int b)
{ //definition
}

int main()
{ //Code in main
  addNumbers(a, b);
}

or this:

#include <stdio.h>

int addNumbers(int, int);
int main()
{ //Code in main
  addNumbers(a, b);
}

int addNumbers(int a, int b)
{ // definition
}
like image 169
Prasoon Saurav Avatar answered Oct 31 '22 11:10

Prasoon Saurav