Home > Software design >  Is a declaration for a non-static data member of a class type also a definition?
Is a declaration for a non-static data member of a class type also a definition?

Time:01-10

I am learning C . In particular, the difference between declaration and definition. To my current understanding

All definitions are declarations but not all declarations are definitions.

Here is an example of what I currently know.

int x; //definition(as well as declaration according to the above quote)
extern int y; //declaration that is not a definition 

class CustomType
{
    int x; //is this a "declaration that is not a definition" OR a "definition"
};
int main()
{
   int p[10]; //definition
   //...
}

I want to know whether int x; inside the class' definition is a declaration that is not a definition or a definition. And where in the standard is this stated so that I can read more about it.

CodePudding user response:

I want to know whether int x; inside the class' definition is a declaration that is not a definition or a definition.

The declaration of a non-static data member (such as x) is a definition.

  •  Tags:  
  • Related