gpt4 book ai didi

c - 数组元素没有变化

转载 作者:太空宇宙 更新时间:2023-11-04 03:39:42 25 4
gpt4 key购买 nike

<分区>

#include<conio.h> 
#include<stdio.h>

void fun(int []);

int main(){

int arr[10] = {1,1,1,1,1};
int i=0;
printf("Before Change : ");
for( i=0;i<5;i++){
printf("%d, ",arr[i]);
}

fun(arr);

printf("\nAfter Change : ");
for( i=0;i<5;i++){
printf("%d, ",arr[i]);
}
getch();
}

void fun(int a[])
{
int i;
for(i=0;i<5;i++){

//a[i] = a[i]++; // Comment 1
//a[i] = ++a[i]; // Comment 2
}
}

当我使用 Comment 1 语句时,我得到以下输出:

更改前:1, 1, 1, 1, 1,

更改后:1, 1, 1, 1, 1,

当我使用 Comment 2 语句时,我得到了这个输出:

更改前:1, 1, 1, 1, 1,

更改后:2, 2, 2, 2, 2,

到这里我知道为什么 Comment 2 Statement get array Change Due to pre increment 了。但我的问题是为什么评论 1 语句不能更改数组元素,因为在其他函数中所做的更改(这里是 fun())能够影响同一数组中的相同更改。

那么为什么数组元素在注释 1 语句中没有改变?

25 4 0
文章推荐: c - openmp 没有利用所有线程
文章推荐: javascript - 内联 onclick 事件返回 "Uncaught SyntaxError: Unexpected token ( "错误
文章推荐: python - 在 matplotlib basemap 正射投影中更改图像背景颜色
文章推荐: html - CSS如何在
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com