Home > Software engineering >  Will this create an object of Sales_data, or it will create variables inside the class?
Will this create an object of Sales_data, or it will create variables inside the class?

Time:09-30

I'm a 13 year old who's trying to learn C . I bought C Primer and I came across something confusing for me:

struct Sales_data {/**/ } acum, trans, * salesptr = nullptr;
    struct Salees_data {};
    Salees_data accumm, transs, * salessptr;

I do understand what is a struct and class but I have no idea what this statement will do. Will it create objects of the Sales_data struct, or it will create variables inside the Sales_data struct?

CodePudding user response:

This defines a Sales_data struct and

  • acum and trans - Two Sales_data instances
  • salesptr - A Sales_data pointer, initialized to nullptr
struct Sales_data {/**/ } acum, trans, * salesptr = nullptr;

This defines a Salees_data struct and

  • accumm and transs - Two Sales_data instances
  • salessptr - A Salees_data pointer, uninitialized
struct Salees_data {};
Salees_data accumm, transs, * salessptr;

or it will create variables inside the Sales_data struct?

No, there are no member variables in either of the class definitions.

I say class definitions because structs are classes too, only with a different default access specifier (public instead of private).

  • Related