看过指针这种输入,输出吗

爵士无理 2018-07-20 01:25:32
........
int i;
char course [5][10], *pcou;
pcou = course[0];
for (i=0,i<5;i++)
{
scanf(" %s ", pcou+10 *i);

}
*****************************************
scanf中的 *i 是什么意思 之前没看过
...全文
208 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
自信男孩 2018-07-23
  • 打赏
  • 举报
回复
乘法符号,就是10 × i;pcou+10 *i就是pcou向后偏移10 * i个字节。
kuake56 2018-07-21
  • 打赏
  • 举报
回复
引用 6 楼 kfyniriu1 的回复:
pcou+10 *i

char是一个字节,pcou+10 *i 表示每次循环向后移10个字节,也就是数组每接收一个字符串,就换到下一行接收下一个字符串。二维数组每一行只保存一个字符串
for语句,第一个是用;不是用,

正确
kuake56 2018-07-21
  • 打赏
  • 举报
回复
二维数组。 每次循环就跳到下一行指向下一行的一维数组开头 一共5行
爵士无理 2018-07-21
  • 打赏
  • 举报
回复
我的天 乌龙了 谢谢大家
kfyniriu1 2018-07-20
  • 打赏
  • 举报
回复
pcou+10 *i

char是一个字节,pcou+10 *i 表示每次循环向后移10个字节,也就是数组每接收一个字符串,就换到下一行接收下一个字符串。二维数组每一行只保存一个字符串

for语句,第一个是用;不是用,
woailaixiangnan 2018-07-20
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
10*i
的意思

10乘以i
不是
10后面紧跟取i这个指针所指的值


回答正确
赵4老师 2018-07-20
  • 打赏
  • 举报
回复
10*i
的意思

10乘以i
不是
10后面紧跟取i这个指针所指的值

赵4老师 2018-07-20
  • 打赏
  • 举报
回复
Pointer Arithmetic
Additive operations involving a pointer and an integer give meaningful results only if the pointer operand addresses an array member and the integer value produces an offset within the bounds of the same array. When the integer value is converted to an address offset, the compiler assumes that only memory positions of the same size lie between the original address and the address plus the offset.

This assumption is valid for array members. By definition, an array is a series of values of the same type; its elements reside in contiguous memory locations. However, storage for any types except array elements is not guaranteed to be filled by the same type of identifiers. That is, blanks can appear between memory positions, even positions of the same type. Therefore, the results of adding to or subtracting from the addresses of any values but array elements are undefined.

Similarly, when two pointer values are subtracted, the conversion assumes that only values of the same type, with no blanks, lie between the addresses given by the operands.
爵士无理 2018-07-20
  • 打赏
  • 举报
回复
回答跑题了 。。。。 我是问 scanf 中 *i 的作用是什么 我之前没看过 这个是一本书里的写法
sghcpt 2018-07-20
  • 打赏
  • 举报
回复
引用 楼主 qq_40750570 的回复:
........
int i;
char course [5][10], *pcou;
pcou = course[0];
for (i=0,i<5;i++)
{
scanf(" %s ", pcou+10 *i);

}
*****************************************
scanf中的 *i 是什么意思 之前没看过


楼主,个人认为,因为pcou指针指向二维数组char* course [5][10],而二维数组course的内存是连续的,所以在for循环的五次执行中,pcou分别指向如下:
1) pcou+ 0 -->等于course[0
2) pcou + 10 -->等于course[1]
3) pcou + 20 -->等于course[2]
4) pcou + 30 -->等于course[3]
5) pcou + 40 -->等于course[4]

即5次输入的scanf类似如下:
1)scanf(" %s ", course[0]);
2)scanf(" %s ", course[1]);
3)scanf(" %s ", course[2]);
4)scanf(" %s ", course[3]);
5)scanf(" %s ", course[4]);

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧