指针的大小 [英] size of pointers
问题描述
我一直在想所有指针(对任何一个obejct)都有相同的
大小。指针的大小是int的大小。这是因为一个int解决了一个内存位置。这是对还是错?
" subramanian" < su ************** @ yahoo.comwrote:
我一直在想所有的指针(对任何一个obejct)有相同的
大小。指针的大小是int的大小。这是因为一个int解决了一个内存位置。这是对还是错?
完全错误,在所有三个方面。
Richard
< blockquote>机器字是32位
sizeof(char)== 1
sizeof(int)== 4
sizeof( char *)== 4
sizeof(int *)== 4
char array [30] =" abc"
char * p =数组;
sizeof(数组)== 30
sizeof(p)== 4
strlen(array)== strlen(p)
strlen(array)== 3
$ b $bóú星期一,2006年12月18日23:32:41 -0800£subramanianD' μ?£o
我一直在想所有指针(对任何一个obejct)都有相同的
大小。指针的大小是int的大小。这是因为一个int解决了一个内存位置。这是对还是错?
subramanian写道:
我一直在想所有指针(对任何一个obejct)有相同的
大小。指针的大小是int的大小。这是因为一个int解决了一个内存位置。这是对还是错?
你错了。指向不同种类物体的指针可能会有不同的尺寸;那个大小不一定是int;内存位置是由指向对象而不是由int指定的
。
I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an int. This is beause a
memory location is addressed by an int. Is that right/wrong?
"subramanian" <su**************@yahoo.comwrote:
I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an int. This is beause a
memory location is addressed by an int. Is that right/wrong?Entirely wrong, on all three counts.
Richard
machine word is 32bit
sizeof(char) == 1
sizeof(int) == 4
sizeof(char *) == 4
sizeof(int *) == 4
char array[30]= "abc"
char *p=array;
sizeof(array) == 30
sizeof(p) == 4
strlen(array) == strlen(p)
strlen(array) == 3
óú Mon, 18 Dec 2006 23:32:41 -0800£?subramanianD′μ?£o
I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an int. This is beause a
memory location is addressed by an int. Is that right/wrong?
subramanian wrote:I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an int. This is beause a
memory location is addressed by an int. Is that right/wrong?You are wrong on all counts. Pointers to different kinds of objects may
have different sizes; that size need not be an int; memory locations are
addressed by a pointer-to-object, not by an int.
这篇关于指针的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!