次のコード
#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;
}
出力
sizeof(string literal) = 2
sizeof(const char* const) = 4
sizeof(const char[]) = 2
GCCでコンパイルされた32ビットOS。
sizeof
文字列リテラルの長さ(に必要なスペース)を計算するのはなぜですか?- 文字列リテラルは、与えられたときに(char *またはchar[]とは)異なるタイプになり
sizeof
ますか?