Declaration (Khai báo)
Trong ngôn ngữ lập trình, khai báo xác định việc nhận dạng, các chủng loại, và các khía cạnh của yếu tố ngôn ngữ như các biến và chức năng. Nó được sử dụng để thông báo sự tồn tại của các yếu tố cho trình biên dịch, đây là một phần quan trọng trong nhiều ngôn ngữ máy (như C), nó yêu cầu các biến được xác định với một khai báo trước khi sử dụng, và được dùng trong khai báo chuyển tiếp.
By English
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, and is used in forward declaration.
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; this allows separating the interface from implementation. 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.