Where do different types (storage class) of data gets stored? - Unix

This is a discussion on Where do different types (storage class) of data gets stored? - Unix ; Where do these different kinds of variables gets stored in memory? I mean what kind of data (initialized, uniniitialized) is stored in what segment of the program (bss, ro, ...) of different storage classes - local, global & static? #include ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Where do different types (storage class) of data gets stored?

  1. Where do different types (storage class) of data gets stored?

    Where do these different kinds of variables gets stored in memory? I
    mean what kind of data (initialized, uniniitialized) is stored in what
    segment of the program (bss, ro, ...) of different storage classes -
    local, global & static?

    #include

    /* global variables */
    int ui; /* uninitialized int */
    int ii = 10; /* initialized int */
    const int ci = 100; /* initialized const int */
    static int usi; /* uninitialized static int */
    static int isi = 10; /* initialized static int */
    const static int csi = 100; /* initialized constant static int */

    char *ucp; /* uninitialized char ptr */
    char *icp = "icp"; /* initialized char ptr */
    const char *ccp = "ccp"; /* initialized const char ptr */
    static char *uscp; /* uninitialized static char ptr */
    static char *iscp = "iscp"; /* initialized static char ptr */
    const static char *cscp = "cscp"; /* initialized constant static char
    ptr */

    int main()
    {
    int main_i; /* uninitialized local int */
    static int main_si; /* uninitialized local static int */
    const int main_ci = 10; /* initialized local const int */
    char *main_cp = "main_cp"; /* initialized local char ptr */
    static char *main_scp = "main_scp"; /* initialized local static char
    ptr */

    return 0;
    }

    Thanks in advance to all who participates this discussion.
    - Magesh


  2. Re: Where do different types (storage class) of data gets stored?

    On Oct 12, 3:55 am, Magesh wrote:
    > Where do these different kinds of variables gets stored in memory? I
    > mean what kind of data (initialized, uniniitialized) is stored in what
    > segment of the program (bss, ro, ...) of different storage classes -
    > local, global & static?
    >
    > #include
    >
    > /* global variables */
    > int ui; /* uninitialized int */
    > int ii = 10; /* initialized int */
    > const int ci = 100; /* initialized const int */
    > static int usi; /* uninitialized static int */
    > static int isi = 10; /* initialized static int */
    > const static int csi = 100; /* initialized constant static int */
    >
    > char *ucp; /* uninitialized char ptr */
    > char *icp = "icp"; /* initialized char ptr */
    > const char *ccp = "ccp"; /* initialized const char ptr */
    > static char *uscp; /* uninitialized static char ptr */
    > static char *iscp = "iscp"; /* initialized static char ptr */
    > const static char *cscp = "cscp"; /* initialized constant static char
    > ptr */
    >
    > int main()
    > {
    > int main_i; /* uninitialized local int */
    > static int main_si; /* uninitialized local static int */
    > const int main_ci = 10; /* initialized local const int */
    > char *main_cp = "main_cp"; /* initialized local char ptr */
    > static char *main_scp = "main_scp"; /* initialized local static char
    > ptr */
    >
    > return 0;
    >
    > }
    >
    > Thanks in advance to all who participates this discussion.
    > - Magesh


    They get stored somewhere. You shouldn't care where.

    The C standard does not dictate where anything should be stored;
    it is up to the compiler to decide how and where to store values.

    Note that some people will tell you that some are stored on the heap,
    and some are stored on the stack, but C has no requirement
    that a heap or stack even exist.
    --
    Fred Kleinschmidt


  3. Re: Where do different types (storage class) of data gets stored?

    >Where do these different kinds of variables gets stored in memory? I

    If I answered "in a dungeon in a basement in Redmond, Washington",
    would it help any? How?

    >mean what kind of data (initialized, uniniitialized) is stored in what
    >segment of the program (bss, ro, ...) of different storage classes -
    >local, global & static?


    A program need not have smegments, or looking at it another way,
    it may have only one.

    The variables declared const and the quoted string constants below
    *might* be put in read-only storage. Or it might not.

    Auto variables (those local to a function and not declared static)
    may have their own smegment, or might not.

    >#include
    >
    >/* global variables */
    >int ui; /* uninitialized int */
    >int ii = 10; /* initialized int */
    >const int ci = 100; /* initialized const int */
    >static int usi; /* uninitialized static int */
    >static int isi = 10; /* initialized static int */
    >const static int csi = 100; /* initialized constant static int */
    >
    >char *ucp; /* uninitialized char ptr */
    >char *icp = "icp"; /* initialized char ptr */
    >const char *ccp = "ccp"; /* initialized const char ptr */
    >static char *uscp; /* uninitialized static char ptr */
    >static char *iscp = "iscp"; /* initialized static char ptr */
    >const static char *cscp = "cscp"; /* initialized constant static char
    >ptr */
    >
    >int main()
    >{
    > int main_i; /* uninitialized local int */
    > static int main_si; /* uninitialized local static int */
    > const int main_ci = 10; /* initialized local const int */
    > char *main_cp = "main_cp"; /* initialized local char ptr */
    > static char *main_scp = "main_scp"; /* initialized local static char
    >ptr */
    >
    > return 0;
    >}
    >
    >Thanks in advance to all who participates this discussion.


    If this is not a homework assignment, why do you need to know?

+ Reply to Thread