Peculiar behaviour with iostream namespace and isalpha function

Revision en4, by ShubhamAvasthi, 2020-02-19 12:15:25

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 namespaces/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.

Tags g++14 compiler, c++ 14, c++, g++, c++ compilers

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en5 English ShubhamAvasthi 2020-02-19 12:17:50 11 Tiny change: ' included namespaces/header fil' -> ' included header fil'
en4 English ShubhamAvasthi 2020-02-19 12:15:25 2 Tiny change: ' namespace/header file for iostr' -> ' namespaces/header files for iostr'
en3 English ShubhamAvasthi 2019-12-25 20:37:52 14
en2 English ShubhamAvasthi 2019-12-25 19:50:40 802 (published)
en1 English ShubhamAvasthi 2019-12-25 14:47:55 168 Initial revision (saved to drafts)