#include <iostream> #include <list> using namespace std; void get_size(char str[100]) { cout<<"size in get_size "<<sizeof(str)<<endl; } int main() { char str[] = "hello"; cout<<"size in main "<<sizeof(str)<<endl; get_size(str); return 0; }
输出:
size in main 6 size in get_size 4 ------------------ (program exited with code: 0) Press return to continue
原因:函数传递字符串为指针传递