0
Print an array
Iâm trying to print array contains the number of from 1 to 5 and i wrote it like Int i, num[5]; For (i=1;i<6;i++) { Cout<<<num[i]; } Then why itâs print unknown numbers like 2783846
8 Answers
+ 2
garbage values.... as you've not initialise the array.
+ 2
Because you are given any values to array. So it is giving garbage values.
First input or initialize array values ,after that print those values...
wojod before that loop, write in another for loop to take inputs by
for(i=0;i<5;i++)
cin>> num[i] ;
give 5 inputs.
+ 1
To initialize a whole array to 0 (or any other value) :
int arr[5] = {0};
0
but i wrote int num[5]
0
exactly garbage values
0
i meant the for to be the input
0
this should help:-
https://www.w3schools.com/cpp/cpp_arrays.asp