我可以在scanf中使用指针来接受数组中的输入吗? [英] Can i use pointer in scanf to take input in an array?

查看:378
本文介绍了我可以在scanf中使用指针来接受数组中的输入吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在的问题中进行此操作:

I am trying to do this in c:

scanf("%d",a+i);

其中,a是大小为10的数组.并且i是循环计数器.那有可能吗?

where a is an array of size 10. And i is counter for loop. So is this possible?

推荐答案

:如果aint*或数组int a[10],并且i在0到9之间,则此表达式有效.

Absolutely: if a is an int* or an array int a[10], and i is between 0 and 9, this expression is valid.

a+i表达式与&a[i]等效,它也是传递给scanf的有效表达式.

The a+i expression is the pointer arithmetic equivalent of &a[i], which is also a valid expression to pass to scanf.

这篇关于我可以在scanf中使用指针来接受数组中的输入吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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