- 1

Can i store a struct in a integer or other variables

if i can then how? and if i cant then how can i store a struct so its easier to write so that i have one name for the struct(s) instead of of making three different programs for each of the structs

28th Apr 2018, 8:51 AM
Nislo Mislo
Nislo Mislo - avatar
4 Respuestas
+ 4
struct coordinate { int x; int y; }; typedef struct coordinate coordinate_t; coordinate_t is now a type, so you can now do this: coordinate_t a, b, c; a.x = 4; a.y = 3; b.x = 6; b.y = 2; c.x = 0; c.y = 7; https://code.sololearn.com/ckQIWJ3y3H7o/?ref=app Note, it's usually better to use classes and not structs in C++.
28th Apr 2018, 9:03 AM
Emma
+ 1
No cause a struct is not an integer type. It doesn't really make sense to do this anyway. If you would provide an example of what you are trying to do here we might be able to help you.
28th Apr 2018, 9:03 AM
TransHedgehog
TransHedgehog - avatar
+ 1
A struct can't be assigned a data type. It is a data type.
2nd May 2018, 12:43 AM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
0
Xan there is no difference between classes and structs in C++, except that struct is public and class is private by default. "Member of a class defined with the keyword class are private by default. Members of a class defined with the keywords struct or union are public by default."
28th Apr 2018, 9:40 AM
Cain Eviatar
Cain Eviatar - avatar