What is the difference between variable declaration and definition in C/C++?

Declaration provides an identify of a variable to the compiler, saying “Hey, there is a variable with certain type here.”

Definition creates a memory space for the variable, which is used to store the data.

The differences are:

1. Declaration does not create memory space but definition does.

2. Same variable may have multiple declaration(external variable), but it can have only one definition.

We can make a declaration and definition at one time, like

int a=1;


This entry was posted in C++. Bookmark the permalink.

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s