i dont understand the output of this code | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 4

i dont understand the output of this code

i dont get the output, isnt is supose to be: 9 3 https://code.sololearn.com/cKCp31a5Ezt1/?ref=app

15th Jun 2019, 7:37 AM
Cat Sauce
Cat Sauce - avatar
2 Réponses
+ 3
Hey. I suspect the problem somewhere here if(grid[i][gx] != NULL) since gx is set to 99 and accessing the array outside its boundaries causes undefined states. C++ starts indexing using "0" so the max index is gx - 1. Try nesting the for loops directly and access the array only in the inner loop, like for (i...){ for (j...) { array[i][j] } } Hope that helps. Cheers.
15th Jun 2019, 11:40 AM
ChrA
ChrA - avatar
+ 3
ChrA fixed it, thanks for(int i = 0;i < gy;i++){ if(grid[i][0] != NULL){ y++; } for(int j = 0;j < gx;j++){ if(grid[i][j] != NULL){ x++; } } } instead of typing gird[i][gx0] i typed grid[i][0] and that fixed it :)
15th Jun 2019, 12:11 PM
Cat Sauce
Cat Sauce - avatar