-2

I have displayed a statement in C++ program with single quote and answer which i got was the random numbers where as when i used the double quotes in C++ it displayed me the statement.

cout << 'Hello world'; //gave me the random numbers
cout << "Hello world"; //displayed me the statement i.e Hello world

Why This happened pls do let me know and what those random numbers were at the time of execution ?

EdChum
  • 376,765
  • 198
  • 813
  • 562
  • 2
    ' are for characters , single ones,, use the "" please for strings, the random stuff you were seeing with the ' are a memory dump of your machine starting from that character up to the first \0 – Gar Jun 10 '16 at 07:42
  • 1
    see this: http://stackoverflow.com/questions/3960954/c-multicharacter-literal – Nim Jun 10 '16 at 07:42
  • 6
    It's a multicharacter literal, check this post : http://stackoverflow.com/questions/7459939/what-do-single-quotes-do-in-c-when-used-on-multiple-characters – Alexis Coquard Jun 10 '16 at 07:53

2 Answers2

0

Single quotes are used for characters:
char c = 'A';

In case you want to print a string which is more than one character, you use double quotes:
cout << "Hello World";

Joe Karam
  • 54
  • 6
0

You are trying to print an array of characters, which require double quotes.

char str[3] = "abc"; //an array of characters, use double quotes
str[0] = 'x';   //set a character in this array, use single quote
Taw
  • 479
  • 3
  • 15