rohitt
rohitt

Reputation: 127

Segments for variables in C programs?

Where are each expression stored in memory? Where would be constant variables stored?

#include<stdio.h>

int a = 0;                   // initialized data segment
char arr[10] = "hello";      // initialized data segment
const int k = -1;            //
int* gptr = &a;              //

int main()
{
    const int m = 31;        //
    int n;                   //
    int* ptr;                //
    ptr = malloc(1024);      // heap segment

    char* ptr2 = &arr;       //

    for(n = 0; n<1024; ++n)  //
        printf("%d ", n);    //
}

Upvotes: 2

Views: 177

Answers (1)

c_mnon
c_mnon

Reputation: 388

GCC would store constants in the text section.

Upvotes: 1

Related Questions