- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are Declarations?
A declaration in a program refers to a statement that provides the data about the name and type of data objects to the programming language translators. For example, consider the following C declaration −
int a, b;
This declaration provides the programming language translator with the information that a and b are the data objects of type integer that are needed during the execution of the subprogram. The declaration also defines the binding of the data objects to the name a and b during their lifetimes.
Purposes of Declaration
The various purposes of declarations are as follows −
Type Checking − The declaration allows the programmers for static type checking i.e., checking the types of data objects at compile time rather than at execution time.
Choice of storage representation − The declaration supports the data about the type of the declared data object which helps the programming language translator to decide the good possible storage representation for that data object. This helps in reducing the overall storage requirement and execution time for the program being translated.
Storage Management − The declarations also serve to indicate the desired lifetime of the data object that creates it possible to use a more effective storage management process during program execution. For example, in C some of the data objects can be declared at the beginning of a subprogram while some other data objects are generated dynamically by the use of a specific function malloc.
Polymorphic Operations − An operation is said to be a polymorphic operation if an operation may take on a variety of implementation depending upon the types of its arguments. The declaration allows the programming language translator to decide at compile time the specific operation named by an overloaded operation symbol. For example in C, the declarations of data object a and b helps in determining the possible addition operation (integer addition or float addition) named by a + b.
Types of Declaration
There are two types of declarations which are as follows −
Explicit Declaration − An explicit declaration is a statement in a program that lists data object names and defines that they are a specific type. The explicit declaration creates a static binding to type. The example of an explicit declaration consists of the following C declaration.
int a, b;
Implicit Declaration − An implicit declaration is a declaration that holds when no explicit declarations are given. For example, in FORTRAN, an identifier that develops in a program that is not explicitly declared is implicitly declared as per the following convention: If the identifier starts with one of the letters I, J, K, L, M, or N it is implicitly declared to be of integer type; otherwise it is implicitly declared to be REAL type.
- Related Articles
- What are forward declarations in C++?
- What are JSP declarations? In how many ways we can write JSP declarations?
- What is typedef declarations in C++?
- What are the rules for external declarations in JShell in Java 9?
- Array Declarations in Java
- Array Declarations in C#
- C# Multiple Local Variable Declarations
- MySQL row declarations for ZF?
- Understanding CSS Selector and Declarations
- Use Declarations in Rust Programming
- What is the difference between Definitions and Declarations in Compiler design?
- Group Use declarations in PHP 7
- Do you think declarations within Python class are equivalent to those within __init__ method?
- Do we need forward declarations in Java?
- Why do Java array declarations use curly brackets?
