top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

what is stack overflow condition which can occur in a C/Java program?

+5 votes
108 views
what is stack overflow condition which can occur in a C/Java program?
posted Sep 19, 2014 by Swati Arora

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Stack overflow happens when the stack pointer exceeds the stack bound. As you can think of it the max amount of memory provided by the system to run your program within that provided memory.

The call stack may consist of a limited amount of address space, often determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture, multi-threading, and amount of available memory.

When a program attempts to use more space than is available on the call stack (that is, when it attempts to access memory beyond the call stack's bounds, which is essentially a buffer overflow), the stack is said to overflow, typically resulting in a program crash.

Condition which can cause the stack overflow :

1.Infinite recursion, For example.

 int main()
 {
     main();   // Here calling main() itself until stack overflow  
     return 0;
  }
  1. Allocating a memory which is bigger the stock memory allocated to you.

    int main()
    {
       double temp[10000000];  //Something like that. if it is not giving the segfault/code crash increase the value.
    }
    
answer Sep 22, 2014 by Arshad Khan
Similar Questions
0 votes

Please help me with a sample program to check whether given matrix is valid sudoku solution or not. Input would be matrix of n*n size and validate grids of sqrt(n)*sqrt(n) size along with row and columns.

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...