Can we call an undeclared function in C++?

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 that doesn’t list argument types:

If we save the below program in a .c file and compile it, it works without any error. But, if we save the same in a .cpp file, it doesn’t compile.

filter_none

edit
close

play_arrow

link
brightness_4
code

#include<stdio.h>
  
void f(); /* Argument list is not mentioned */
  
int main()
{
   f(2); /* Poor style in C, invalid in C++*/
   getchar();
   return 0;
}
  
void f(int x)
   printf("%d", x);
}
chevron_right

Source: http://www2.research.att.com/~bs/bs_faq.html#C-is-subset

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

Article Tags :
C
Practice Tags :