PDA

View Full Version : Difference between ' & "



Atomic_Sheep
24th January 2013, 11:35
I have a basic program:


char chTest;
chTest = 'a';
qDebug() << chTest;

However if I use "a", it spits out an error at me - 47: error: invalid conversion from 'const char*' to 'char'

What does that error mean? And why does it occur?

wysota
24th January 2013, 11:54
char c = 'a'; // one character
char *str = "a"; // string literal

Santosh Reddy
24th January 2013, 13:06
However if I use "a", it spits out an error at me - 47: error: invalid conversion from 'const char*' to 'char'
Error says it, keeping the const qualifier aside in the error ouput, looks like you are converting from 'char' to 'char*'.

'char' and 'char*' are different types and cannot be assigned / implicitly converted.

When you bring in const back in discussion. One can convert 'const char*' to 'char*', but other way 'char*' to 'const char*', is not implicitly possible.