top of page

Difference between Declaration, Definition & Initialisation of a Variable

Updated: Jun 23

In C programming, the terms declaration, definition, and initialisation refer to different stages of a variable's lifecycle.


Understanding the difference is key to writing correct and efficient code.


🔹 1. Declaration

  • What it is: Tells the compiler that a variable exists, but doesn't allocate memory (unless it's also a definition).

  • Why it's used: Usually for external variables (defined elsewhere).

  • Syntax:

    extern int x;

  • Memory allocated? ❌ No

  • Value assigned? ❌ No


🔹 2. Definition

  • What it is: Allocates memory for the variable. If not declared before, it's also treated as a declaration.

  • Why it's used: To actually create the variable.

  • Syntax:

    int x; // Definition (and declaration, if not done before)

  • Memory allocated? ✅ Yes

  • Value assigned? ❌ No (value is indeterminate if uninitialised)


🔹 3. Initialisation

  • What it is: Assigning an initial value to a variable at the time of definition.

  • Why it's used: To start the variable with a known value.

  • Syntax:

    int x = 10;

  • Memory allocated? ✅ Yes

  • Value assigned? ✅ Yes


✅ Summary Table

ree

 
 
 

Comments


CONTACTUS

AutoEConnect Limited

AutoEConnect Limited

Tel. +44 - 750 819 6789

    +44- 73490 29529

 1 Parker Close, Rugby
Warwickshire, United Kingdom

CV21 1NY

AutoEConnect India

Tel. +91 - 950 520 1250

 Vaibhav Complex, Second Floor,

Near Reliance Mart,

 Ramachandrapuram

Andhra Pradesh, India 533255

Social Media Links
  • LinkedIn
  • Facebook
  • YouTube

AutoEConnect
Website Traffic Data

TELLUS

AutoEConnect.com: Suggestions & Feedbacks help us stay motivated and to do better. We would love to hear from you.

AutoEConnect Limited: For collaborations or enquiries on our services, please connect with us using the form below.

 

Thanks for contacting us. We will get back to you shortly!

©2025  AutoEConnect.com

bottom of page