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 "
?
In US English, you must use double quotation marks. Single quotation marks are used for quotes within quotes. In UK English, it's most common to use single quotation marks, with double quotation marks for quotes within quotes, although the other way around is acceptable too.
The main difference between double quotes and single quotes is that by using double quotes, you can include variables directly within the string. It interprets the Escape sequences. Each variable will be replaced by its value.
If you're referring to what happens when you echo something, the single quotes will literally echo what you have between them, while the double quotes will evaluate variables between them and output the value of the variable.
Single quotation marks are also known as 'quote marks', 'quotes', 'speech marks' or 'inverted commas'. Use them to: show direct speech and the quoted work of other writers. enclose the title of certain works.
Single-quotes denote a character literal. Double-quotes denote a string literal.
So '-'
is of type char
1, whereas "-"
is of type const char[2]
(which typically decays to const char *
).
int
in C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With