user3696933
user3696933

Reputation: 69

do we have more memory space for static variables?

int dp[2009][2009]

static int dp[2009][2009];

I made a c++ program in which i declared an arry as
int dp[2000][2000] the program stopped working due to very much memory allocation .when i declared it as static
int dp[2009][2009] , the program worked fine . whats the reason for this ??

Upvotes: 1

Views: 403

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477020

Variables with automatic storage can only use a small, implementation-dependent amount of space ("the stack"). By contrast, variables with static storage duration can use a much larger amount of space, constrained mostly by the global machine constraints.

Unfortunately, there is no mechanism within the language to tell you how much space is available for automatic variables. It's an implementation-dependent limit that when you overstep it produces undefined behaviour, but you cannot know what the limit is or how much you have left...

Upvotes: 5

Related Questions