

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain the Difference Between Definition and Declaration
In this post, we will understand the difference between definition and declaration.
Definition
Definition, with respect to a function indicates that the body of the function has been developed.
With respect to variable, it means a value has been associated/defined with that variable.
A function can be defined only once.
Once a function or variable has been defined, it is ready to be used.
A variable can be re-defined multiple times, as and when required. This depends on the language and the scopes.
Memory is allocated when function or a variable is defined.
Below is an example of variable definition
sum = 0
A variable named ‘sum’ is assigned to 0.
Below is an example of function definition
def add_val(param_1, param_2) c = param_1 + param_2 return c
The ‘add_val’ is a method, and ‘param_1’ and ‘param_2’ are parameters passed to it. There is a definition of this method too.
Declaration
Function declaration basically means that a name has been given and the parameters have been mentioned.
No value is associated with a variable when it is just declared.
Its body hasn’t been developed yet.
Once a function or variable has been declared, it is not yet ready to be used.
A function or variable can be declared any number of times.
Memory isn’t allocated when a function or variable is declared.
Below is an example of variable declaration −
sum_val
A variable named ‘sum_val’ is declared.
Below is an example of function declaration −
add_val(p_1, p_2)
The ‘add_val’ is a method, and ‘p_1’ and ‘p_2’ are parameters passed to it. There is no definition of the method.
- Related Questions & Answers
- Difference between Definition and Declaration in Java.
- What is the difference between declaration and definition in C#?
- What is the difference between a definition and a declaration in C++?
- Explain the difference between Virus and Worm?
- Explain the difference between OLAP and OLTP
- Internal Table itab declaration in SAP and difference between both the declarations
- Explain the difference between physical and logical databases
- Explain the variable declaration, initialization and assignment in C language
- Explain the difference between RowSet and ResultSet in JDBC?
- Explain the difference between getColumnHeaders(), getColumnNames() and getColumnTitles() in SAP?
- Explain the difference between static and dynamic binding in Java.
- Explain the Difference Between Linear and Non-linear Data Structure
- Explain the difference between const and readonly keywords in C#
- Convert NFA to DFA and explain the difference between them
- Explain difference between Abstraction and Encapsulation in PHP.