如何获取指向数组的指针的大小。

编程入门 行业动态 更新时间:2024-10-24 06:37:15
本文介绍了如何获取指向数组的指针的大小。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

鉴于以下代码 包括< stdio.h> #include< stdlib.h> int main(无效){ char * msg_list [] = {" apple,"橙色,葡萄" }; printf(" name:%s \ n",msg_list [0]); printf(" size:%d \\ \\ n",sizeof(msg_list)); 返回0; } 我以为拿尺码(msg_list)会给我字符串的大小 " apple" (即6)。相反,我得到了以下的: 名称:苹果 尺寸:12 我在这里缺少什么? 乍得

Given the following code include <stdio.h> #include <stdlib.h> int main(void) { char *msg_list[] = {" apple", " orange", " grape" }; printf("name: %s \n", msg_list[0]); printf("size: %d \n", sizeof(msg_list)); return 0; } I thought taking sizeof(msg_list) would give me the size of the string "apple" (ie 6). Instead, I get the following: name: apple size: 12 What I''m missing here? Chad

推荐答案

乍得说: Chad said: 给出以下代码 包含< stdio.h> # include< stdlib.h> int main(void){ char * msg_list [] = {" apple,"橙色,葡萄" }; printf(" name:%s \ n",msg_list [0]); printf(" size:%d \\ \\ n",sizeof(msg_list)); 返回0; } 我以为拿尺码(msg_list)会给我字符串的大小 " apple" (即6)。相反,我得到了以下的: 名称:苹果 尺寸:12 我在这里缺少什么? Given the following code include <stdio.h> #include <stdlib.h> int main(void) { char *msg_list[] = {" apple", " orange", " grape" }; printf("name: %s \n", msg_list[0]); printf("size: %d \n", sizeof(msg_list)); return 0; } I thought taking sizeof(msg_list) would give me the size of the string "apple" (ie 6). Instead, I get the following: name: apple size: 12 What I''m missing here?

msg_list是一个由三个指向char的数组。在你的平台上,它出现,每个指向char的指针占用四个字节。因此, 数组的大小是3 * 4 = 12.在其他系统上,你可能得到不同的结果。 (例如,在MS-DOS下,你可能会很好获得3 * 2 = 6,而在一些 DSP上你可能得到3 * 1 = 3.) sizeof msg_list [0]会给你一个字符的大小*。 sizeof" apple",但是,无论平台的价值是多少,你都会得到6个你想要的东西。 - Richard Heathfield Usenet是一个奇怪的地方 - dmr 29/7/1999 www.cpax.uk 电子邮件:rjh在上面的域名(但显然放弃了www)

msg_list is an array of three pointers-to-char. On your platform, it appears, each pointer-to-char occupies four bytes. Hence the size of the array is 3 * 4 = 12. On other systems, you might get different results. (For example, under MS-DOS you might well get 3 * 2 = 6, whereas on some DSPs you might get 3 * 1 = 3.) sizeof msg_list[0] would give you the size of a char *. sizeof "apple", however, will give you the 6 you expected to get, regardless of the platform. -- Richard Heathfield "Usenet is a strange place" - dmr 29/7/1999 www.cpax.uk email: rjh at above domain (but drop the www, obviously)

Richard Heathfield写道: Richard Heathfield wrote: Chad说: Chad said: 给出以下代码 包括< stdio.h> #include< stdlib.h> int main(void){ char * msg_list [] = {" apple,"橙色,葡萄" }; printf(" name:%s \ n",msg_list [0]); printf(" size:%d \\ \\ n",sizeof(msg_list)); 返回0; } 我以为拿尺码(msg_list)会给我字符串的大小 " apple" (即6)。相反,我得到了以下的: 名称:苹果 尺寸:12 我在这里缺少什么? Given the following code include <stdio.h> #include <stdlib.h> int main(void) { char *msg_list[] = {" apple", " orange", " grape" }; printf("name: %s \n", msg_list[0]); printf("size: %d \n", sizeof(msg_list)); return 0; } I thought taking sizeof(msg_list) would give me the size of the string "apple" (ie 6). Instead, I get the following: name: apple size: 12 What I''m missing here?

msg_list是一个由三个指向char的数组。在你的平台上,它出现,每个指向char的指针占用四个字节。因此, 数组的大小是3 * 4 = 12.在其他系统上,你可能得到不同的结果。 (例如,在MS-DOS下,你可能会很好获得3 * 2 = 6,而在一些 DSP上你可能得到3 * 1 = 3.) sizeof msg_list [0]会给你一个字符的大小*。 sizeof" apple",但是,无论平台的价值是多少,你都会得到6个你想要的东西。

msg_list is an array of three pointers-to-char. On your platform, it appears, each pointer-to-char occupies four bytes. Hence the size of the array is 3 * 4 = 12. On other systems, you might get different results. (For example, under MS-DOS you might well get 3 * 2 = 6, whereas on some DSPs you might get 3 * 1 = 3.) sizeof msg_list[0] would give you the size of a char *. sizeof "apple", however, will give you the 6 you expected to get, regardless of the platform.

无论如何都要从这种结构中获得苹果的大小而不用 必须输入 sizeof" apple"

Is there anyway to get the size of apple from this construction without having to type sizeof "apple"

Chad写道: Chad wrote: Richard Heathfield写道: Richard Heathfield wrote: >> Chad说: >>Chad said: >>>给出以下代码 包括< stdio.h> #include< stdlib.h> int main(无效){ ch ar * msg_list [] = {" apple,"橙色,葡萄" printf(" name:%s \ n",msg_list [0]); printf(" size:%d \ n",sizeof(msg_list) ); 返回0; } 我认为拿sizeof(msg_list)会给我字符串的大小" apple" (即6)。相反,我得到以下内容: 名称:苹果大小:12 我在这里缺少什么? >>>Given the following codeinclude <stdio.h>#include <stdlib.h>int main(void) { char *msg_list[] = {" apple", " orange", " grape" }; printf("name: %s \n", msg_list[0]); printf("size: %d \n", sizeof(msg_list)); return 0;}I thought taking sizeof(msg_list) would give me the size of the string"apple" (ie 6). Instead, I getthe following:name: applesize: 12What I''m missing here?

msg_list是一个由三个指向char的数组。在你的平台上,它出现,每个指向char的指针占用四个字节。因此,数组的大小为3 * 4 = 12.在其他系统上,您可能会得到不同的结果。(例如,在MS-DOS下,您可能会得到3 * 2 = 6,而在某些 DSP上你可能得到3 * 1 = 3.) sizeof msg_list [0]会给你一个char *的大小。 sizeof"然而,无论平台是什么,苹果都会给你6个你期望得到的东西。

msg_list is an array of three pointers-to-char. On your platform, itappears, each pointer-to-char occupies four bytes. Hence the size of thearray is 3 * 4 = 12. On other systems, you might get different results.(For example, under MS-DOS you might well get 3 * 2 = 6, whereas on someDSPs you might get 3 * 1 = 3.)sizeof msg_list[0] would give you the size of a char *.sizeof "apple", however, will give you the 6 you expected to get, regardlessof the platform.

无论如何都要获得这种结构的苹果大小没有 必须输入 sizeof" apple"

Is there anyway to get the size of apple from this construction without having to type sizeof "apple"

strlen( "苹果"); ?????????????????

strlen("apple"); ??????????????????????????

更多推荐

如何获取指向数组的指针的大小。

本文发布于:2023-07-29 00:48:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235705.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   指针   大小

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!