Does a structure declaration really take memory?

struct books
{
    char name[100];
    float price;
    int pages;
};

Declaring a structure Without creating objectin structure, does the structure take up space in memory for its own DATA MEMBERS?

+4
source share
3 answers

A structure definition is usually not part of the binary in C. It exists only in your source code.

( , , ..), , , ( ).

, , , .

, , .

+6

?

- , , . , .

:

const struct books myBooks = { ...initialization code... }; \\ Consuming CODE memory (typically ROM)

struct books myBooks = { ...initialization code... }; \\ Consuming DATA memory (typically RAM)

+2

No. In a compiled type of program, declarations / definitions exist only as concepts of compilation time. They do not leave traces in the compiled code and do not affect memory consumption at runtime. Storage in program C is occupied by objects. Types are not objects.

+1
source

Source: https://habr.com/ru/post/1525466/


All Articles