使用指针初始化数组 [英] initializing array using pointer

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

问题描述

假设我有一个指向整数数组的指针。我使用指针初始化数组的每个元素?plz解释

suppose i have a pointer to an array of integers.can i initialize each
member of the array using pointers?plz explain

推荐答案




您可以使用指针为数组元素赋值。看下面的代码




main()

{

int array [3 ];

int * pArry,count;


pArry = array;


* pArry = 1; pArry ++;

* pArry = 2; pArry ++;

* pArry = 3;


for(count = 0; count< 3; count ++)

printf( array [%d]包含%d \\\\ n,count,array [count]);


}


这就是你想要的。


问候,

Saurabh。


arun写道:
Hi,

You can assign values to array elements using pointer. Look at the code
below:

main ()
{
int array[3];
int *pArry, count;

pArry = array;

*pArry = 1; pArry++;
*pArry =2; pArry++;
*pArry =3;

for (count = 0; count <3; count++)
printf ("array[%d] contains %d\r\n",count, array[count]);

}

Is this what you want.

Regards,
Saurabh.

arun wrote:
假设我有一个指向整数数组的指针。我使用指针初始化数组的每个
成员?plz explain
suppose i have a pointer to an array of integers.can i initialize each
member of the array using pointers?plz explain






arun写道:
假设我有一个指向整数数组的指针。我用指针初始化数组的每个
成员?plz explain
suppose i have a pointer to an array of integers.can i initialize each
member of the array using pointers?plz explain




你的意思是:


#define ARR_MAX 100

int arr [ARR_MAX];

int * myptr;

int i;


myptr = arr;

for(i = 0; i< ARR_MAX; i ++){

* myptr = 0;

myptr ++;

}



You mean something like:

#define ARR_MAX 100

int arr[ARR_MAX];
int *myptr;
int i;

myptr = arr;
for(i=0; i<ARR_MAX; i++) {
*myptr = 0;
myptr++;
}


问题不明确。

Question not clear.


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

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