In which part of memory different variables get stored? Who will assign the value to it before starting main?

76 views Asked by At

As per my understanding, There are four part of memory.

  • Data Segment (BSS, Non BSS)
  • Code Segment
  • Heap Segment
  • Stack Segment

Stack segment will store all the local variables declared inside the function. Dynamically created variable will go inside heap. Initialized global variable will inside data segment - BSS area. Non-Initialized global variable will inside data segment - Non BSS area. All const variable & macro will go inside code area.

We can instruct the compiler to store particular variable at particular location inside the memory using #pragma.

I don't know where does const pointer and pointers get stored. is it inside data segment?

Please let me know my understanding is correct or not?

I have code:

#include <stdio.h>
#include <stdlib.h>

#define MAX 10
enum color{
    RED,
    GREEN,
    BLUE
};

int a;
int b=5;
static int c;
static int d=10;
extern int e;
const int f;
const int g = 15;
const int *ptr1;
int *ptr2;

int main(void) {
    // your code goes here
    int h;
    int i=20;
    static int j;
    static int k=25;
    const int l;
    const int m = 30;
    int *ptr3;
    const int *ptr4;

    return 0;
}

In this code, where does these variable a to m will get stored?

0

There are 0 answers