Difference between C++ string constants and character constants

C++ProgrammingObject Oriented Programming

In C++, a character in single quotes is a character literal. It's of type char. For example, 'a' is of type char with a value 97 on an ASCII based system.

A character or a string of characters together in double quotes represent a string literal. It's of type const char[] and refers to an array of size length of string + 1. That extra character is there for marking the string's ending.

String literals can be arbitrarily long, such as "abcdefg". Character literals almost always contain just a single character. When these are being printed, string literals are printed till the first \0 or NULL character is encountered in the string.

raja
Published on 16-Feb-2018 14:32:31
Advertisements