#include<iostream>
using namespace std;
int main()
{
int abc();
return 0;
}
When the compiler reaches the line int abc();, it rightly thinks that we are declaring a function named abc which does not take any arguments and whose return type is of type int. Then why is the compiler not throwing me an error because I have not defined a function named abc?
It is not an error to declare a function without defining it. The function could have been defined in another file. In C++, each compilation unit (C++ file) is compiled individually, and linked together after that.
Linker does not show error either, because you don't attempt to use the function. If you attempted to use it, linker would search all compilation units for the definition, and show error when it does not find a definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With