Coderbyte is an online coding challenge site (I found it just 2 minutes ago).
The first C++ challenge you are greeted with has a C++ skeleton you need to modify:
#include <iostream> #include <string> using namespace std; int FirstFactorial(int num) { // Code goes here return num; } int main() { // Keep this function call here cout << FirstFactorial(gets(stdin)); return 0; }
If you are little familiar with C++ the first thing* that pops in your eyes is:
int FirstFactorial(int num);
cout << FirstFactorial(gets(stdin));
So, ok, the code calls gets
which is deprecated since C++11 and removed since C++14 which is bad in itself.
But then I realize: gets
is of type char*(char*)
. So it shouldn't accept a FILE*
parameter and the result shouldn't be usable in the place of an int
parameter, but ... not only it compiles without any warnings or errors, but it runs and actually passes the correct input value to FirstFactorial
.
Outside of this particular site, the code doesn't compile (as expected), so what is going on here?
*Actually the first one is using namespace std
but that is irrelevant to my issue here.