Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaration or Definition

Tags:

c++

Is this, line of code that is presented below and under this sentence, considered a declaration or definition?

extern const int &ri;
like image 817
Jeeves Avatar asked Nov 18 '25 14:11

Jeeves


2 Answers

It's a declaration- the "extern" means that it lives somewhere else.

like image 182
Puppy Avatar answered Nov 20 '25 03:11

Puppy


C++03, §3.1, ¶2:

A declaration is a definition unless ... it contains the extern specifier or a linkage- specification and neither an initializer nor a function-body ...

So, extern const int &ri;, which contains the extern specifier and not an initializer is a declaration but not a definition.

like image 34
Robᵩ Avatar answered Nov 20 '25 03:11

Robᵩ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!