sizeof(指针变量名)及sizeof(数组名)
#include 

int main(int argc, char* argv[])
{
	char a[] = "hello world!";
	char *b;
	char c[3];
	char *d = "world";

	printf("sizeof a=%d\n", sizeof(a));	// 返回数组大小
	printf("sizeof b=%d\n", sizeof(b));	// 返回指针大小
	printf("sizeof c=%d\n", sizeof(c)); // 返回指针大小
	printf("sizeof d=%d\n", sizeof(d)); // 返回数组大小

	return 0;
}
C++

32位机器上程序的输出结果为:

a=13
b=4
c=3
d=4
Bash
由此可见,sizeof(数组名)会返回数组的大小(数组元素数量*sizeof(数组类型))(对于字符串数组包含末尾的空),而sizeof(指针变量名)会返回指针变量本身的大小。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇