What is the meaning of single quotes and double quotes in comparison?

This returns an error:

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

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

However, it is not:

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

What is the difference between ' and " ?

+6
source share
1 answer

Single quotation marks indicate an alphabetic character. Double quotes indicate a string literal.

So, '-' is of type char 1 whereas "-" is of type const char[2] (which usually splits into const char * ).


1 int in C.
+22
source

Source: https://habr.com/ru/post/905378/


All Articles