Блог пользователя ShubhamAvasthi

Автор ShubhamAvasthi, история, 4 года назад, По-английски

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.

  • Проголосовать: нравится
  • +24
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by ShubhamAvasthi (previous revision, new revision, compare).

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by ShubhamAvasthi (previous revision, new revision, compare).

»
4 года назад, # |
Rev. 3   Проголосовать: нравится +5 Проголосовать: не нравится

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.