Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the significance of single quotes vs double quotes in comparisons? [duplicate]

Tags:

c++

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 " ?

like image 870
Calvin Froedge Avatar asked Jan 07 '12 03:01

Calvin Froedge


People also ask

What is the difference between using single and double quotation marks?

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.

How does using single versus double quotation marks differ in creating or printing strings?

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.

What is the use of single and double inverted commas in Echo?

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.

What do single quotation marks represent?

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.


1 Answers

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.
like image 122
Oliver Charlesworth Avatar answered Oct 11 '22 13:10

Oliver Charlesworth