A declaration establishes the names and characteristics of data objects and functions used in a program. A definition allocates storage for data objects or specifies the body for a function. When you define a type, no storage is allocated.
Declarations determine the following properties of data objects and their identifiers:
The declaration for a data object includes one or more of:
Note:
#include <iostream.h>
void main()
{
int a, b;
cout << "Please enter two integers" << endl;
cin >> a >> b;
int d = a + b;
cout << "Here is the sum of your two integers:" << d << endl;
}
The following table shows examples of declarations and
definitions.
| Examples of Declarations and Definitions | |
| Declarations | Declarations and Definitions |
| "extern double pi;" | "double pi = 3.14159265;" |
| "float square(float x);" | "float square(float x) { return x*x; }"
|
| "struct payroll;" | struct payroll {
char *name;
float salary;
} employee;
|
![]()
Declarators
Initializers
Syntax of a Data Declaration
Type Specifiers