6

This returns an error:

return (arg[0] == "-" && arg[1] == "-") ? true : false;

error: ISO C++ forbids comparison between pointer and integer

However, this does not:

return (arg[0] == '-' && arg[1] == '-') ? true : false;

What is the difference between ' and " ?

laurent
  • 88,262
  • 77
  • 290
  • 428
Calvin Froedge
  • 16,135
  • 16
  • 55
  • 61

1 Answers1

22

Single-quotes denote a character literal. Double-quotes denote a string literal.

So '-' is of type char1, whereas "-" is of type const char[2] (which typically decays to const char *).


1 int in C.
Martin York
  • 257,169
  • 86
  • 333
  • 562
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680