I have very strange problem while I am submitting a practice problem on codechef. Where the solution ” having global declaring of 2D char array” is getting accepted while the one with “Declaration inside the main function” is getting rejected as wrong answer.
Below are links for solution.
1) Having global declaration : http://www.codechef.com/viewsolution/1138654
2) Having Delaration inside main() : http://www.codechef.com/viewsolution/1138660
PS1: I am not using the 2D char array outside the main function.
PS2: I talking about the array ” char boardString[1000][1000] “;
Because you probably run out of stack space.
When you declare an array globally it gets allocated in the data/Bss segment(Note this is implementation detail)
While, when you declare a array in
main()it gets created locally on the stack(Again a implementation detail)Since the array you are allocating is huge(
1000 X 10000) you might run out of stack space.Codechef is intelligent enough to detect this problem and hence it rejects the code with array in
main()as a wrong answer.