Generally variables are stored in heap memory. When he
variables are created in stack?

Answers were Sorted based on User's Feedback



Generally variables are stored in heap memory. When he variables are created in stack?..

Answer / vadivelt

It is wrong to say that genarally variables will be stored
in heap memmory.

Bcos Storage area always depends on the storage class of
the variable.

According to the C standard the storage will be.
1.variable with storage class 'auto' ie., local to the
function - in stack memory.
2.variable with storage class 'extern' and 'static' in data
segment.
3.variable with storage class 'register' in processor
register. But this register variable will be treated as
auto when there is no enough memory in the processor.

Is This Answer Correct ?    15 Yes 0 No

Generally variables are stored in heap memory. When he variables are created in stack?..

Answer / rohit repale

It is wrong to say that genarally variables will be stored
in heap memmory.
Bcos Storage area always depends on the storage class of
the variable.
If the variables are created by new i.e. dynamic memory is
created then it use heap memory.
static & extern variables are stored in static memory.
And other normal variables are stored in stack.

Is This Answer Correct ?    3 Yes 0 No

Generally variables are stored in heap memory. When he variables are created in stack?..

Answer / suneet

According to the C standard the storage will be.
1.variable with storage class 'auto' ie., local to the
function - in stack memory.
2.variable with storage class when 'extern' and 'static' are initialized stored in data segment otherwise found in bss.
3.variable with storage class 'register' in processor
register. But this register variable will be treated as
auto when there is no enough memory in the processor.

Is This Answer Correct ?    2 Yes 0 No

Generally variables are stored in heap memory. When he variables are created in stack?..

Answer / rahul

I am not sure about this answer but when you pass any
argument to any recursive or non-recursive function.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C++ General Interview Questions

class Foo { public: Foo(int i) { } }; class Bar : virtual Foo { public: Bar() { } }; Bar b; Referring to the above code, when the object 'b' is defined, a compiler error will occur. What action fixes the compiler error? a) Adding a virtual destructor to the class Bar b) Adding a constructor to Bar which takes an int parameter c) Adding "Foo()" to the Bar constructor d) Adding a copy constructor to the class Foo e) Adding "Foo(0)" to the Bar::Bar initializer list

2 Answers   Quark,


What do you mean by storage classes?

1 Answers  


which is the easy way to divide any integer by 2?

2 Answers   Persistent,


Write a struct time where integer m, h, s are its members?

0 Answers  


declare an array of structure where the members of the structure are integer variable float variable integer array char variable access all elements of the structure using dot operator and this pointer operator

0 Answers  






Can we delete this pointer in c++?

0 Answers  


How can I learn dev c++ programming?

0 Answers  


a class that maintains a pointer to an object that is programatically accessible through the public interface is known as?

2 Answers   CTS,


Do you know what is overriding?

0 Answers  


Explain the register storage classes in c++.

0 Answers  


what is a reference variable in C++?

0 Answers  


Why null pointer is used?

0 Answers  


Categories