C Strings

Having to use individually single quoted characters separated by a comma is quite clumsy, and therefore error prone, but thankfully there's a shorthand method of utilising a double quoted literal string of characters:

 

e.g. char myString[] = "Yamaha" ;

 

A string contained in double quotes is actually an array of constant characters, terminated with a null character '\0'. Thus the above double quoted string example consists of 8 characters including the null!

 

#include <iostream>
using namespace std;

int main () {

	char myString[] = "Yamaha" ;

	cout << myString ;

	return 0;
}

Compile & Run:

Yamaha

Leave a Reply