• Networking
  • Programming
  • DBMS
  • Operating System
  • Internet
  • Hardware
  • Software

Tech Differences

Know the Technical Differences

Difference Between Definition and Declaration

definition vs declarationDefinition and Declaration are very confusing terms if you are new to programming. The two concepts are different in some ways as the definition involve memory assignment to the variables while in declaration memory is not allocated. The declaration can be done more than one time, conversely, an entity can be defined exactly once in a program.

The definition is automatically a declaration in most of the scenario. Now let’s understand the difference between definition and declaration with the detailed comparison chart.

Content: Definition Vs Declaration

    1. Comparison Chart
    2. Definition
    3. Key Differences
    4. Example
    5. Conclusion

Comparison Chart

Basis for comparisonDefinitionDeclaration
BasicDetermines the value stored in variable, function or class.Specifies the name and type of variable, function, class, etc.
Memory allocationOccursDoes not take place.
RepetitionStatements cannot be defined again if once it is already defined.Redeclaration can be easily possible.
ScopeDuration is determinedVisibility is specified

Definition of Definition

Definition identifies the code or data associated with the name of the variable, function, class, etcetera. The definition is necessarily required by the compiler to allocate the storage space for the declared entity. When a variable is defined it holds an amount of memory consist of several bytes for that variable. A function definition produces code for the function. We can define a program element just once in a program because the definition is a unique specification of a program element. The relationship between declaration and definition can be one-to-many.

In some situations, a program element cannot be defined but declared, for example when a function is never invoked or its address is never used even if it is declared. Another example is that in which the class definition is not used while it must be declared.

Definition of Declaration

Declaration is used to specify the names to the program such as the name of a variable, function, namespace, classes, etc. No name can be used in a program without its declaration. The program elements can be declared multiple times, unlike definition. Multiple declarations can only be achieved when the different declarations are made using the identical format. Declaration is the medium of providing visibility to the program element in the perspective of compilers.

The declaration serves the purpose of definition, only in certain cases the condition is not implied which are given below.

  • When the static data member is declared inside a class declaration, in that case, it is not a declaration. Because it generates only one copy for all objects of the class and static data members are the components of the objects of a provided class type.
  • If a declaration is typedef statement.
  • A variable is declared without initializer or function body but includes extern specifiers. It indicates that the definition could be for the other function and provides the name external linkage.
  • The class name declaration without including definition such as class T;

Usually, declaration takes place in a scope. The scope decides the visibility of the name declared and the defined object duration.

Key Differences Between Definition and Declaration

  1. The definition of a program element determines the value associated with that element. On the other hand, the declaration of a program element specifies its name and type to the compiler.
  2. The definition of the program element reserves some amount of memory while declaration doesn’t involve memory allocation.
  3. A program element can be declared multiple times. Conversely, definition incorporates a unique specification with the name of the program element which could be distinguished by any code or data.
  4. Scope in declaration describes the visibility of the variable, function, object, class, enumeration, etc. In contrast, in the definition the scope relates to the duration.

Definition Example

  • Variable definition as well as the declaration:
    int r = 10;
  • Function definition:
    int add (int x , int y)
    {
    int a;
    a = x + y;
    return a;
    }

Declaration Example

  • Variable declaration:
    extern int r;
  • Function declaration:
    int add (int p1, int p2);

Conclusion

The declaration process is used to make the program element visible to the compiler, and it doesn’t require to allocate the memory. Inversely definition is a declaration that reserve storage, in simple words the compiler reserves the memory space for the declared entity.

Related Differences:

  1. Difference Between Stack and Queue
  2. Difference Between One-Dimensional (1D) and Two-Dimensional (2D) Array
  3. Difference Between Array and Linked List
  4. Difference Between Local and Global Variable
  5. Difference Between Pointer and Reference

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Top 10 Differences

  • Difference Between OLTP and OLAP
  • Difference Between while and do-while Loop
  • Difference Between Guided and Unguided Media
  • Difference Between Preemptive and Non-Preemptive Scheduling in OS
  • Difference Between LAN, MAN and WAN
  • Difference Between if-else and switch
  • Difference Between dispose() and finalize() in C#
  • Difference Between for and while loop
  • Difference Between View and Materialized View
  • Difference Between Server-side Scripting and Client-side Scripting

Recent Addition

  • Difference Between Java and Python
  • Difference Between PHP and HTML
  • Difference Between GPS and GNSS 
  • Difference Between Virtualization and Containerization
  • Difference Between Storage and Memory

Categories

  • Artificial Intelligence
  • DBMS
  • Hardware
  • Internet
  • Networking
  • Operating System
  • Programming
  • Software

Copyright © 2025 · Tech Differences · Contact Us · About Us · Privacy