×

declaring an array of 1000000 size

 0 I was seeing a solution of a problem in the solution an array is declared as int vec[1000000] when i copied the code and tried to run it on my system it gives me error but when i submitted the same code on codechef i got correct answer. while searching for the cause i found out that i cant declare array of that size because stack memory is limited. i should declare it in heap using dynamic memory allocation but my question is that how i got correct answer on codechef ? asked 27 Aug '13, 01:22 101●12●15●26 accept rate: 0%

 2 I'm not saying this will totally work and solve your problem but, if you declare your array globally then, i think even on old gcc compiler this will work. answered 27 Aug '13, 10:37 3★sobhagya 2.7k●13●27●47 accept rate: 12% yes its working. but y? (27 Aug '13, 16:52) 2 Global variables are allocated in the heap memory, which is the memory where dynamically allocated memory resides. Non-global variables are allocated in the stack which is typically much, much shorter... This a good trick to have present as it might help you even with newer compiler versions... :) (27 Aug '13, 17:12) kuruma3★ same as @kuruma (27 Aug '13, 21:53) sobhagya3★ thanks it helped me in clearing some basic concepts..:) (28 Aug '13, 00:31)
 1 Hello, It might be possible that your compiler flags are somewhat "ill-defined", in the sense that you don't allow so much stack memory to be used which basically means your stack-size has a different size limit than the one used by Codechef judge, but, I compiled that code in my system and it gave no errors or warnings... I am using this to compile it: gcc -Wall -ansi -pedantic -o teste teste.c -lm This is my gcc version status: gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  You should re-check your compiler settings, as if the code works fine on my system and on Codechef, then the problem must be on your side... Hope this helps!! Best regards, Bruno answered 27 Aug '13, 01:47 3★kuruma 17.7k●72●143●209 accept rate: 8%
 0 when i checked my gcc version it showed gcc 3.4.2 copyright (c) 2004 i think its too old and that's why its stack memory will be less than its current version. thanks alot answered 27 Aug '13, 03:03 101●12●15●26 accept rate: 0% I'm glad I could help you :) (27 Aug '13, 04:05) kuruma3★
 0 I was having same problem while compiling some problem of codechef, but when i submitted it, got ac... answered 27 Aug '13, 21:35 309●2●12 accept rate: 3% @abcdexter24 read my answer first (27 Aug '13, 21:52) sobhagya3★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×836
×105

question asked: 27 Aug '13, 01:22

question was seen: 12,867 times

last updated: 28 Aug '13, 00:31