# C/C++ 知识点---sizeof使用规则及陷阱分析 原文出处:【[胖奇的专栏](http://blog.csdn.net/chenqi514)】 1、什么是sizeof 首先看一下sizeof在msdn上的定义: ​ The sizeof keyword gives the amount of storage, in bytes, associated with a variable or a type (including aggregate types). This keyword returns a value of type size_t. 看到return这个字眼,是不是想到了函数?错了,sizeof不是一个函数,你见过给一个函数传参数,而不加括号的吗?sizeof可以,所以sizeof不是函数。网上有人说sizeof是一元操作符,但是我并不这么认为,因为sizeof更像一个特殊的宏,它是在编译阶段求值的。举个例子: | 1 2 | cout< using namespace std; int Sum(int i[]) { int sumofi = 0; for (int j = 0; j < sizeof(i)/sizeof(int); j++) //实际上,sizeof(i) = 4 { sumofi += i[j]; } return sumofi; } int main() { int allAges[6] = {21, 22, 22, 19, 34, 12}; cout< using namespace std; int Sum(int *i, unsigned int n) { int sumofi = 0; for (int j = 0; j < n; j++) { sumofi += i[j]; } return sumofi; } int main() { int allAges[] = {21, 22, 22, 19, 34, 12}; cout<