Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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
*/
 
PREVIOUS NEXT
Tagged: #change #array
ADD COMMENT
Topic
Name
3+9 =