Interview Questions and Answers :: HCL Technologies
Home > Experience Archives > HCL Technologies > Interview Question Set 1 > Discussion
11. Can you tell me simple program of stack corruption.
Answer:
#include
int main(void)
{
int a=0;
a = 1;
main();
return 0;
}
In the above piece of code, we declare a variable 'a' inside main() and recursively call main() again and again. Now since every time main() gets called, a memory chunk on stack is allocated for main() again and again. Now, lets run the code :
Manish
10 Apr, 2017 2:18 AM
#include
int main(void)
{
int a=0;
a = 1;
main();
return 0;
}
In the above piece of code, we declare a variable 'a' inside main() and recursively call main() again and again. Now since every time main() gets called, a memory chunk on stack is allocated for main() again and again. Now, lets run the code :
Report Error
Report Error
Please Login First Click Here