Why the use of alloca() is discouraged?

Answers were Sorted based on User's Feedback



Why the use of alloca() is discouraged? ..

Answer / johnson

Sorry, that is not strictly correct. According to the man page:

"The alloca() function allocates size bytes of space in the
stack frame of the caller, and returns a pointer to the
allocated block. This temporary space is automatically freed
when the caller returns."

Now this is the real reason:
" If the allocated block is beyond the current stack limit,
the resulting behavior is undefined."

Is This Answer Correct ?    12 Yes 0 No

Why the use of alloca() is discouraged? ..

Answer / sathish kumar

Hi All,

If you use alloca inside a function when it retuns from
function it will be resulting in memory leak. Thats why
its discouraged to use.

Thanks & Regards
Sathish Kumar

Is This Answer Correct ?    2 Yes 5 No

Post New Answer

More C Interview Questions

What is the acronym for ansi?

0 Answers  


a=0; while(a<5) printf("%d\n",a++); how many times does the loop occurs? a.infinite b.5 c.4 d.6

7 Answers   TCS,


What is variable initialization and why is it important?

0 Answers  


what will be maximum number of comparisons when number of elements are given?

0 Answers  


what is pointer ? what is the use of pointer?

6 Answers   Infosys,






What are the salient features of c languages?

0 Answers  


Are c and c++ the same?

0 Answers  


Is c is a procedural language?

0 Answers  


main() { printf("\n %d %d %d",sizeof('3'),sizeof("3"),sizeof(3)); }

6 Answers  


When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd

0 Answers  


What is stack in c?

0 Answers  


What is %g in c?

0 Answers  


Categories