- 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
4 Answers
+ 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++.
+ 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.
+ 1
A struct can't be assigned a data type. It is a data type.
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."