What is the difference between the following two initializations for a Struct
?
Car ford = {
.name = "Ford F-150",
.price = 25000
};
And:
Car dodge = (Car) {
.name = "Ram",
.price = 1000
};
From Compiler Explorer, it looks like the two produce the same code:
What does the (StructName)
do when preceding the struct? It seems its necessary when doing complex initializations such as:
CarPtr mazda = & (Car) {
.name = "Mazda",
.price = 20000
};
Also related, to the two answers from Possible to initialize/assign a struct pointer?.