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

6th Dec 2019, 7:50 PM
wojod
8 Answers
+ 2
garbage values.... as you've not initialise the array.
6th Dec 2019, 7:52 PM
rodwynnejones
rodwynnejones - avatar
+ 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.
6th Dec 2019, 7:54 PM
Jayakrishna 🇼🇳
+ 1
To initialize a whole array to 0 (or any other value) : int arr[5] = {0};
6th Dec 2019, 9:01 PM
Théophile
Théophile - avatar
0
but i wrote int num[5]
6th Dec 2019, 7:53 PM
wojod
0
exactly garbage values
6th Dec 2019, 7:53 PM
wojod
0
i meant the for to be the input
6th Dec 2019, 7:55 PM
wojod
6th Dec 2019, 8:19 PM
rodwynnejones
rodwynnejones - avatar