How to use a structure constructor in an array of structures
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Feb 18, 2014, 6:52 AM EST
Please refer the link
http://stackoverflow.com/questions/7079206/how-to-initialize-array-of-struct
VulpesRank #55 · 29.2K reputationPosted Feb 18, 2014, 10:37 AM EST
This is because each element of the struct array is automatically given its default values when the array is created.
Consider, for example, this example:
The output is:
Of course, if you want to give the structs non-default values initially then you can use a struct constructor as in the link which Lakshmanan found.