The implicit declaration of function error is very common in C language. Either you are a beginner in C or moved to C from a high-level language. C is procedural programming language. So it is very important to declare every function before using. The flow control works on Top-Down basis.
int main() { callit(1, "12"); /* Declare that function before using it */ return 0; } int callit(int x, char *p) { /* Some Code */ }The actual error message is
warning: implicit declaration of function
What causing Implicit declaration of function error in C?
This error will generally show the name of the function in the compiler. You are using the function without declaring it. A more in-depth solution Implicit declaration of function in C is available here.
Solution of Implicit declaration of function
1) If you are using pre-defined function then it is very likely that you haven’t included the header file related to that function. Include the header file in which that function is defined.
#include <unistd.h>2) If you are using any custom function then it is a good practice to declare the function before main. Sometimes the problem comes due to the return type of the function. By default, C language assumes the return type of any function as ‘int’. So, declare the function before main, that will definitely resolve that issue.
int callit(int x, char *p); /* Declare it in this way before main */Final Words
If you are still getting any problem, then feel free to comment down your code.
Makarios Ousta says
#include
int main()
{
int x = 1, y = 3;
printf(“%d %d\n”, x, y);
what (x, y);
printf(“%d %d\n”, x, y);
return 0;
}
void what(int a, int b)
{
a = a+1;
b = ++b;
}
My Easy Tuts Ankit says
Hi Makarios,
As the post suggests, you should declare the function before using it. This will resolve the error.
Jeet says
You might have called function first and then created function later …
Make sure when you call function it should be written before it.
Farah says
#include
#include
int main()
{
sayHi (“mike”);
return 0;
}
void sayHi (char name[]){
printf(“hello %s”, name);
}
sravan says
#include
int main()
{
int dec,bin;
printf(“Enter a decimal number:”);
scanf(“%d”,&dec);
bin=convert(dec);
printf(“The binary equivalent of %d is %d.\n”, dec, bin);
return 0;
}
int convert(int dec)
{
if (dec == 0)
{
return 0;
}
else
{
return (dec % 2 + 10 * convert(dec / 2));
}
}
sravan says
main.c:7:9: warning: implicit declaration of function ‘convert’ [-Wimplicit-function-declaration]
plz slove this
Tushar Kumar says
Declare your function before your main function.
->
#include
int convert(int dec);
int main()
{
int dec,bin;
printf(“Enter a decimal number:”);
scanf(“%d”,&dec);
bin=convert(dec);
printf(“The binary equivalent of %d is %d.\n”, dec, bin);
return 0;
}
int convert(int dec)
{
if (dec == 0)
{
return 0;
}
else
{
return (dec % 2 + 10 * convert(dec / 2));
}
}
TILAK says
#include
void starpattern(int rows)
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j <= rows; j++)
{
printf("*");
}
printf("\n");
}
}
void starreversepattern(int rows)
{
for (int i = rows; i < 0; i–)
{
for (int j = 0; j <= rows; j++)
{
printf("*");
}
printf("\n");
}
}
void main()
{
int rows;
pintf("Enter the rows you want to print\n");
scanf("%d", &rows);
starpattern(rows);
starreversepattern(rows);
}
Avinash says
great thanks buddy