当前位置:三九宝宝网 → 宝宝教育 → 教学论文 → 正文

C语言声明数组参数的问题

更新:03-23 整理:39baobao.com
字体:

[c语言中数组名作为函数参数]要将数组长度作为一个参数传给average函数,不能在average函数内部通过int arrLen = sizeof(a) / 4;来计算数组长度。因为float average(float a[10])就相当于float average(fl...+阅读

看下面代码:int main(){ int a[5]={3,6,4,2,5}; char *ptrChar="hello world";//ptrChar是char类型的指针,指向内存空间 int *ptrInt=a;//ptrInt是指向int类型的指针 printf("sizeof(char):%d\n",sizeof(char)); printf("sizeof(int):%d\n",sizeof(int)); printf("sizeof(ptrChar):%d\n",sizeof(ptrChar)); printf("sizeof(ptrInt):%d\n",sizeof(ptrInt)); printf("value of ptrChar is:%d\n",ptrChar); printf("value of (ptrChar+1) is:%d\n",ptrChar+1); printf("value of ptrInt is:%d\n",ptrInt); printf("value of (ptrInt+1) is:%d\n",ptrInt+1); system("pause"); return 1;}程序运行结果如下:从程序的运行结果可以得出:指针本身是一个变量,它所存储的是另一个变量的地址,指针变量所占的内存是4个字节,这与它所指向的变量所占的内存空间大小是没有关系的,指针变量本身和它所指向的内存空间是完全独立的...

c中数组如何声明

楼主看看我的 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace How_to_use_Array { class Program { static void Main() { /***************************** 一维数组 *******************************/ //int[] myint = new int[4] { 1, 2, 3, 4 }; /*声明方式一*/ //int[] myint; //myint = new int[4] { 1, 2, 3, 4 }; /*声明方式二*/ //int[] myint = { 1, 2, 3, 4 }; /*声明方式三*/ //for (int i = 0; i

C语言编程声明数组的问题

#include

#include

#include

int main()

{

void StaticArray();

void array();

void DynamicArray();

int i = 500000;

clock_t start, finish;

double duration;

printf ("完成 %ld 次函数调用所需要的时间是: ", i) ;

start = clock();

while (i--)

{

StaticArray();

array();

DynamicArray();

}

finish = clock();

duration = (double)(finish - start) / CLOCKS_PER_SEC;

printf ("%f 秒\n", duration);

return 0;

}

void StaticArray()

{

static int a[1000];//静态整型数组

}

void array()

{

int a[1000];//在栈上声明数组

}

void DynamicArray()

{

int *p = (int *) malloc (1000 * sizeof(int));//动态声明数组

}

本文地址:https://www.39baobao.com/show/29_49152.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

c语言:关于参数传递数组嗯,一般传递数组是这样的: int a[3]={1,2,3}; //定义数组 void fun(int [],int length); //申明函数,第一个参数是数组头地址,第二个参数是数组长度 fun(a,sizeof(a)/sizeof(int))...

C语言二维数组做函数参数数组行和列都是自己输入的#include "stdio.h" main() { int i,j,a[2][2],max,flag=0; printf("enter the grade.\n"); for(i=0;ifor(j=0;jscanf("%d",&a[i][j]); max=a[0][0]; for(i=0;ifor(j=0;jif(max fo...

C语言数组做参数#include void fun(int a[10]) { int t,i; for(i=0;i<5;i++) { t=a[i]; a[i] = a[5+i]; a[5+i] = t; } } void main( ) { int c[10]={1,2,3,4,5,6,7,8,9,10},i; fun(c); for...

C语言中关于数组名作为函数参数方面的问题不知道你说的第2,4,5语句对应的是什么。。。。 帮你解释为什么是1: 1. 当你调用fun(a,b,s); 传进的参数实际上是:&a[0], &b[0], s变量的值(实际上也就是&a[0]) 2. 现在我们把fu...

关于c语言中数组作为函数参数的函数之间调用问题1、新建一个数组作为参数项目,如图所示: 2、添加一个array.c文件,如图所示: 3、包含stdio.h和stdlib.h头文件,如图所示: 4、输入main函数主体及返回值,如图所示: 5、定义一个数...

c语言编程指针数组作为函数参数#include #include int main() { void sort1(char **p1); void print(char **p2); static char *name[]={"zhang","wang","li","zhao","abe"}; sort1(name); print(name); return 0; }...

c语言数组作为函数参数怎样写如果一个函数的目的是要产生一个新的数组,那么最好的做法是在调用函数前就生成好这个数组,然后把这个数组作为参数传给函数,在函数中修改这个数组的值. 像你这种做法,在sum函数...

c语言全局变量可声明问题如果static和extern都没有,表示定义一个全局变量,其作用域限制在从定义开始到当前文件结尾。 static的作用是将全局变量的作用域限制在从定义开始到当前文件结尾,且其他文件不...

C语言函数声明的问题我也来 说几句。。 标准编译器 对函数的调用 都要 先申明 才能 调用 (生产的时候就这样设定的)。。我推荐试用 大点的 vs2005,vc2000. 小点的 Dev-cpp ,Turboc 3.0 (2.0 不支...