I have to solve a simple quest : a func1() //(in C) that change the last element of an array
but with input:
2
10 20
I receive this 4218948 4218948 (!?)
I typed the following code:
#include<stdio.h>
void cng_it(int *arr3, int x){
arr3[x - 1] = 100;
}
int main()
{
int n2;
scanf("%d ", &n2);
int arr4[n2];
for(int i = 0; i < n2; i++){
scanf("%d ", &arr4[i]);
}
cng_it(arr4,n2);
for(int i = 0; i < n2; i++){
printf("%d", arr4[n2]);
if(i < n2 - 1){printf(" ");}
}
return 0;
}
I do not know where to throw the head !!
Can someone help me to finding the bug?
New contributor
pvt-Tron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.