Answers for "how to change a value from an array c++"

C++
1

how to change a value from an array c++

/*
if you want to change the value that is i th from the left of the array called 
'arr' and give it a value of 'x'
*/
int arr[7] = {1,2,3,4,5,6,7};
int x = 5;
int i = 2;
arr[i-1] = x;
/* 
before : arr = {1,2,3,4,5,6,7}
after : arr = {1,5,3,4,5,6,7}
we use [i-1] because indexes of an array starts from 0 instead of 1
*/
Posted by: Guest on April-29-2022

Code answers related to "how to change a value from an array c++"

Browse Popular Code Answers by Language