top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can we use scanf and printf functions in our C program without including header file? Please explain the reasoning also?

0 votes
545 views
Can we use scanf and printf functions in our C program without including header file? Please explain the reasoning also?
posted Jul 5, 2017 by Ajay Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
 
Best answer

Printf() and Scanf() are predefined function of the stdio.h file. And unless you declare and define a function, you cannot call it or in short you have to include header file.

Above explanation was applicable for any standard C compiler and these days C compiler also gone through many transformation for good and my C compiler does not give error if you dont include stdio.h (assuming it may be including internally)

answer Jul 5, 2017 by Salil Agrawal
//given below program work properly in DEV C++ without using any header file
#define square(x) x*x

int square1(int x)
{
  return x*x;  
}

main()
{
    int a;
    printf("Enter a number:\t");
    scanf("%d",&a);
    printf("A = %d\n",a);
   printf("Macro output - %d\n", square(2+2));
   printf("Function output - %d\n", square1(2+2));
}
/*Output:

Enter a number: 11
A = 11
Macro output - 8
Function output - 16*/
Yes that what I said modern compiler auto include if not included for most of the header file but that is not the standard C behavior. Even my gcc compiler compiles a program without stdio.h.
...