Sizeof String Literal: Unraveling the Differences
Consider the following code snippet:
#include <iostream> using namespace std; int main() { const char* const foo = "f"; const char bar[] = "b"; cout << "sizeof(string literal) = " << sizeof("f") << endl; cout << "sizeof(const char* const) = " << sizeof(foo) << endl; cout << "sizeof(const char[]) = " << sizeof(bar) << endl; }
Executing this code reveals intriguing results:
sizeof(string literal) = 2 sizeof(const char* const) = 4 sizeof(const char[]) = 2
Understanding the Results
The above is the detailed content of What's the Difference Between `sizeof` a String Literal, a `const char* const`, and a `const char[]`?. For more information, please follow other related articles on the PHP Chinese website!