I am beginner in c++. Here is my doubt why in this program they are again creating struct variable from the previously created struct object ? Here is the example:
typedef struct prog1
{
int a,b;
}*obj1;
int main()
{
obj1 moc=new prog1(); // why again creating object for *obj1 object?
moc->a=10; // why dont we use obj1 -> a=10;
}
thanks
obj1 is not an object but a type definition, because it is part of the typedef definition. Namely, it is a type of prog1* (a pointer to prog1). The obj1 moc declares a variable of this type, i.e. moc is a pointer to prog1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With