Introduction
Strings are an essential part of programming and programming language. In C/C++, there are two ways to represent them: string literals and character arrays. In this blog, we will delve deep into the string literals and character arrays in C/C++.
String Literal:
Definition:
A string literal in C/C++ is a sequence of character enclosed in double quotation marks. For example:
const char* strLiteral = "Hello, World!";
Characteristics:
- Read-only Memory: String literals are stored in read-only memory, which means attempting to modify them directly results in undefined behavior.
- Null-terminated: String literals are null-terminated, meaning they end with a null character (
\0
), marking the end of the string.