- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between C++ string constants and character constants
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.
Advertisements