I tested the following code with three different compilers and saw some peculiar results. First of all, I am not sure why the program compiles (no errors with isalpha) indicating that cctype/ctype.h is being automatically included allowing the compilation of the program.
As far as I know and according to cplusplus.com, neither cctype namespace nor ctype.h header file is amongst the automatically included header files for iostream. Also, iostream does not inherit from cctype/ctype.h.
#include <iostream>
using namespace std;
int main()
{
cout<<isalpha('a');
}
On my local machine with MinGW (32 bit), it prints 2.
On Codeforces compiler, it prints 2.
On ideone, it prints 1024.
All the above compilations were done for C++14.
It would be great if someone could share the reason for this behaviour.
Auto comment: topic has been updated by ShubhamAvasthi (previous revision, new revision, compare).
Auto comment: topic has been updated by ShubhamAvasthi (previous revision, new revision, compare).
Regarding the output value:
I have gone through the same mistake once. The actual reason is here: http://www.cplusplus.com/reference/cctype/isalpha/?kw=isalpha
Unlike you would expect, it doesn't return a boolean value, but returns some integer value that is some non-0 value in case the input char is an alphabet.
Yes, I read that too but anyway added the outputs as well in the question. It is probably an implementation dependent thing.
I am mostly concerned with why the code compiles in the first place.
It's an implementation dependent thing. Headers are allowed to include each other outside the standard specification. Of course, it's not something you can rely on. Similar questions have been asked here:
Thanks! That answers my query.