Search
 
SCRIPT & CODE EXAMPLE
 

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
*/
Comment

PREVIOUS NEXT
Code Example
Cpp :: cpp binary tree 
Cpp :: c++ template example 
Cpp :: c++ if in equivalent 
Cpp :: delete a node from binery search tree c++ 
Cpp :: how to remove an element from a vector by value c++ 
Cpp :: c++ vector pop_back 
Cpp :: c++ typing animation 
Cpp :: how to do sets in cpp 
Cpp :: overload stream insert cpp 
Cpp :: ray sphere intersection equation 
Cpp :: clear the input buffer in cpp 
Cpp :: find max element in array c++ 
Cpp :: inbuilt function to convert decimal to binary in c++ 
Cpp :: sort 0 1 2 leetcode 
Cpp :: create a 2d vector in c++ 
Cpp :: detect end of user input cpp 
Cpp :: deque c++ 
Cpp :: break in c++ 
Cpp :: std vector c++ 
Cpp :: cannot jump from switch statement to this case label c++ 
Cpp :: how to read files in c++ 
Cpp :: union of two arrays leetcode 
Cpp :: function in c++ 
Cpp :: unordered_set to vector 
Cpp :: how to use toString method in C++ 
Cpp :: C++ code for Dijkstra’s Algorithm 
Cpp :: life the universe and everything solution c++ 
Cpp :: cuda shared variable 
Cpp :: size() in c++ SET 
Cpp :: how to create a file in c++ 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =