Difference between ' and "

Solved
stell-91 Posted messages 519 Registration date   Status Member Last intervention   -  
Dalfab Posted messages 638 Registration date   Status Member Last intervention   -
Hello,

I'm having a bit of trouble with programming because I think I don't understand the difference between " and '.
If I understand correctly, in a program when I do "x" it will display the character x as output.
But if I do 'x' what is the difference? Why use 'x'?

Thank you for your explanations

Configuration: Windows / Chrome 59.0.3071.115

1 answer

Felice_ Posted messages 271 Status Member 11
 
Hello stell-91,

Single quotes are for characters while double quotes are for strings.

For example, you cannot write in C:
'string' but you can write "string".

In fact, the character corresponding to an integer in the ASCII table is a character, while the other is an array made up of characters.

Did you come from a high-level language like PHP, Python, Ruby, or another?
1
stell-91 Posted messages 519 Registration date   Status Member Last intervention   5
 
Thank you for your explanations. Just with the first two lines, I had understood. But now it's even clearer.

No, I'm starting out.
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > stell-91 Posted messages 519 Registration date   Status Member Last intervention  
 
Hello, can you mark the issue as resolved?
0
stell-91 Posted messages 519 Registration date   Status Member Last intervention   5
 
To come back to what you told me "chain" is ok 'a' is fine too "a" stays good, but 'chain' is wrong?

Do you confirm?
0
Dalfab Posted messages 638 Registration date   Status Member Last intervention   102 > stell-91 Posted messages 519 Registration date   Status Member Last intervention  
 
Yes,
A string contains characters and a terminator:
"chaine" is composed of the characters 'c' 'h' 'a' 'i' 'n' 'e' and the terminator denoted by '\0'
"a" is composed of the character 'a' and the terminator '\0'
"" is an empty string, it contains only the terminator character '\0'
0