It is OK to do so. Because the variable int printf
you defined do not belong to the namespace std
as printf
, which is defined in cstdio
. So there is actually no conflict in names of your program.
However, if you declare
using namespace std;
before your program, and no std::
used later in your program, then it'll cause problems if you're not careful. Generally, when there is name conflicts, compiler will use the name defined in smallest scope. So if you have program like:
#include<cstdio>
using namespace std;
int main()
{
int printf = 42;
printf("%d", printf);
}
The compiler will return
error: ‘printf’ cannot be used as a function
This is because in this program, printf
is defined as a int
in function scope, and as a function int printf( const char* format, ... )
in global scope. Since function scope is smaller than global scope, in function int main()
, printf
is intepreted as int
rather than function. int
is not callable, hence the error message.