Declaration (computer Programming)
In programming languages, a declaration specifies the identifier, type, and other aspects of language elements such as variables and functions. It is used to announce the existence of the element to the compiler; this is important in many strongly typed languages (such as C) that require variables and their types to be specified with a declaration before use.
In the BCPL family languages such as C++ and Java, it can also specify the variable's dimensions to declare a scalar, array or matrix. In this family, "pure" declarations (announcing the existence and properties of the element, commonly called simply "declarations") and definitions (declarations that provide the actual implementation in the case of functions, and initialization in the case of variables) can be made independent of each other. Declarations are generally made in header files, which are meant to be included in other files that reference and use these declarations, but don't have access to the definition. If a definition type doesn't match the previous declaration for the same element, the situation generates a compiler error.
For variables, definitions assign values to an area of memory that was reserved during the declaration phase. For functions, definitions supply the function body. While a variable or function may be declared many times, it is typically defined once. Dynamic languages such as JavaScript or Python allow redefining of functions.
A declaration is often used in order to be able to access functions or variables defined in different source files, or in a library.
Here are some examples of declarations that are not definitions, in C:
extern char example1; extern int example2; void example3(void);Here are some examples of definitions, again in C:
char example1; int example2 = 5; void example3(void) { int x = 7; }Read more about Declaration (computer Programming): Variables
Famous quotes containing the word declaration:
“I foresee the time when the painter will paint that scene, no longer going to Rome for a subject; the poet will sing it; the historian record it; and, with the Landing of the Pilgrims and the Declaration of Independence, it will be the ornament of some future national gallery, when at least the present form of slavery shall be no more here. We shall then be at liberty to weep for Captain Brown. Then, and not till then, we will take our revenge.”
—Henry David Thoreau (18171862)