GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Does declaration of variable allocates memory in C?

In C, Whether memory will be allocated when the variable is declared? For ex, does statement int a; allocates memory for a?

asked Nov 13, 2015 by ArvindGilkinja

2 Answers

 
Best answer

Yes, when you declare a variable like int a;

Memory is allocated it can seen by running the code

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    cout<<&a;
    return 0;
}

This prints the address of the variable.What does that mean?. It means that variable exist in memory.

link to code is: http://code.geeksforgeeks.org/0A6Fhw

answered Nov 13, 2015 by passion34
selected Nov 13, 2015 by ArvindGilkinja
...