The Structure of Declarations

Declarations is specifying the properties of an identifier. In c++, the declaration have five parts:

• Optional prefix specifiers like static, extern etc
• A base type like int, char, const float etc
• A declarator like p[7] , n etc
• Optional suffix function specifiers like const, noexcept etc
• An optional initializer or function body like =34, (2), {1}, { return 1;} etc

A specifier is an initial keyword, such as virtual, extern or constexpr that specifies some non-type attribute of what is being declared.

So, Any declaration whether it is variable or function will have above five parts which three are optional parts.

e.g.

static int function() const {    return x;
}
int a = 12;

Except for function and namespace definitions, a declaration is terminated by a semicolon.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s