Does all the members inherit const, or only the variable p is read-only and for this its members are not accessible?
The members don't inherit anything. You have marked the variable declaration as const, so you can only initialize in the initialization itself. The const qualifier can be applied to the fields themselves, if you want them not to be modified in the code.
Just assume that something that has been qualified const is not assignable (you can initialize it at declaration, as you do in your sample code, but never after that) You could have qualified e.g.
struct point {
const char * const name;
int x, y;
};
and then use:
struct point var = { .name = "origin", .x = 0, .y = 0 };
now you can
var.x = 3; var.y = 5;
but not
var.name = "not the origin anymore";
because name is a const qualified field.
And of course, if you declare:
const struct point origin = { "origin", 0, 0 };
the whole variable is const and you cannot change it at all.
constand its members not? Would the compiler give you a warning if you attempted to assign the entire structure at once but not if you attempted to assign individual members? Would that be useful?const int i = 5;. You do know that the variableiwill then be a constant, and you can't modify the value ofi? It's the same here: You definepas a constant object. It might be easier if we introduce a type-alias for the structure:typedef struct point point_type;. Then you can doconst point_type p = { 1, 2 };. Is that easier to understand?