Implicit declaration of function

If you use CodeBlock for  compelling C/C++ programs you might face this kind of warning 

suppose, if you got warning such as “implicit declaration of function ‘exit’ “ that means  you need to include header file #include<stdlib.h> before you use exit function in any program

for example, consider below program

#include <stdio.h>
//#include <stdlib.h>
int main () {
   FILE *fp;// file pointer fp
   int length;
   fp = fopen("text.txt", "r");
    if(fp==NULL) // check if the file contain NULL character
        printf("\n file cannot be open"); // if yes then print, file cannot be open
   fseek(fp, 0, SEEK_END);
   length = ftell(fp);
   printf("Total size of text.txt = %d bytes\n", length);

Another example

You need to include header file <string.h> to use function  strcpy otherwise, you might face error like “implicit declaration of function ‘strcpy’ “

#include <stdio.h>
//#include <string.h> // you need to include header <string.h> to avoid implicit declaration
int main() {
   char string1[10] = "hi_there";
   char string2[10];
   // copies the  s1 to s2
   strcpy(string2, string1);
   return 0;

Mohammed Anees

Hey there, welcome to aneescraftsmanship I am Mohammed Anees an independent developer/blogger. I like to share and discuss the craft with others plus the things which I have learned because I believe that through discussion and sharing a new world opens up

Leave a Reply

Your email address will not be published.