4

I would to know why the second parameter of the standard function strchr is an integer knowing that it will be casted to a char ?

The prototype :

strchr(const char *s, int c)
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Elie Teyssedou
  • 749
  • 1
  • 7
  • 19
  • `int c` is means the character that you want to search. The character is passed as an integer, but in fact only the lower 8 bits are searched. It should therefore be handed over to a char – Michi Nov 23 '15 at 17:35
  • So it is the same as tolower(), isspace(), memset(), memchr(), strrchr(), putchar(), etc. Consistency is important :) – Hans Passant Nov 23 '15 at 17:35
  • It's for consistency with versions of `strchr` in old K&R versions of C which had no prototypes and arguments narrower than an `int` would be promoted to `int`. – Ian Abbott Nov 23 '15 at 18:20

0 Answers0