找到数组的大小 [英] Find the size of an array

查看:78
本文介绍了找到数组的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个相同大小的数组的新数组

可用:

#include< stdio.h>

#include< string.h>


int main(无效)

{

char arrc [] =" ; URI" ;;

const int asize = sizeof(arrc)/ sizeof(arrc [0]);

char new_arr [asize];


printf(" new_arr size =%d \ n",sizeof(new_arr));


返回0;

}


========================输出============== ======

[arnuld @ dune C] $ gcc4 -ansi -pedantic -Wall -Wextra test.c

test.c:在函数中? maina ??:

test.c:9:警告:ISO C90禁止可变大小数组a ?? new_arra ??

[arnuld @ dune C] $ ./ a.out

new_arr size = 4

[arnuld @ dune C] $


该程序给出正确答案。但为什么警告。 sizeof()编译

时间运算符然后为什么我得到一些与运行时相关的警告?



-
www.lispmachine.wordpress.com

我的电子邮件是@上面的博客。

Google Groups现在是UnBlocked :)

I want to create a new array of the same size of an array already
available:
#include <stdio.h>
#include <string.h>

int main(void)
{
char arrc[] = "URI";
const int asize = sizeof(arrc) / sizeof (arrc[0]);
char new_arr[asize];

printf("new_arr size = %d\n", sizeof(new_arr));

return 0;
}

======================== OUTPUT ====================
[arnuld@dune C]$ gcc4 -ansi -pedantic -Wall -Wextra test.c
test.c: In function a??maina??:
test.c:9: warning: ISO C90 forbids variable-size array a??new_arra??
[arnuld@dune C]$ ./a.out
new_arr size = 4
[arnuld@dune C]$

The program gives correct answer. But Why the warning. sizeof() is compile
time operator then why do I get some warning related to run-time ?


--
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is UnBlocked now :)

推荐答案

gcc4 -ansi -pedantic -Wall -Wextra test.c

test.c:在函数中?? ?? maina ??:

test.c:9:警告:ISO C90禁止变量大小的数组a ?? new_arra ??

[arnuld @ dune C]
gcc4 -ansi -pedantic -Wall -Wextra test.c
test.c: In function a??maina??:
test.c:9: warning: ISO C90 forbids variable-size array a??new_arra??
[arnuld@dune C]


./ a.out

new_arr size = 4

[arnuld @ dune C]
./a.out
new_arr size = 4
[arnuld@dune C]





程序给出正确答案。但为什么警告。 sizeof()编译

时间运算符然后为什么我得到一些与运行时相关的警告?



-
www.lispmachine.wordpress.com

我的电子邮件是@上面的博客。

谷歌群组现在是UnBlocked :)


The program gives correct answer. But Why the warning. sizeof() is compile
time operator then why do I get some warning related to run-time ?


--
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is UnBlocked now :)


这篇关于找到数组的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆