cpp_playground/misc/sizeof.cpp
wangjiacai 9c26dc803d
All checks were successful
continuous-integration/drone/push Build is passing
add sizeof(char*) for comparison
2022-11-28 15:34:03 +08:00

28 lines
615 B
C++

#include <iostream>
using namespace std;
char strs[2][1024];
size_t sizeof_by_pchar(char *str)
{
return sizeof(str);
}
size_t sizeof_by_char_arr(char str[])
{
return sizeof(str);
}
int main()
{
cout << sizeof(strs) << endl;
cout << sizeof(strs[0]) << endl;
cout << sizeof(strs[0][0]) << endl;
for (size_t i = 0; i < sizeof(strs) / sizeof(strs[0]); i++)
{
cout << "sizeof array: " << sizeof(strs[i]) << endl;
cout << "param by char pointer: " << sizeof_by_pchar(strs[i]) << endl;
cout << "param by char array: " << sizeof_by_char_arr(strs[i]) << endl;
}
}