liveBook · Manning

Declaration

As explained in Modern C, Third Edition

A C declaration specifies the kind of entity an identifier refers to without necessarily allocating storage or supplying its concrete value.

Before an identifier can be used in C, it must be declared: the compiler needs to know what that name represents. Keywords are different; the language defines them, so they are not declared. TAKEAWAY: Declare identifiers before using them. section 2.2

int main(int, char*[]);
int argc;
[[maybe_unused]] char* argv[];
double A[5];
size_t I;

These declarations associate names with types and shapes. Parentheses mark main as a function; brackets mark A and argv as arrays. In double A[5], the five elements have indices 0 through 4. The attribute on argv indicates that it may go unused. section 2.2

A declaration does not, by itself, tell you an object's concrete value or where it is stored. That is the role of a definition. In the introductory cases, adding an initializer to a variable declaration also defines its object and provides an initial value. A function declaration becomes a definition when followed by a body in braces. TAKEAWAY: Declarations specify identifiers; definitions specify objects. section 2.3 section 2.1

Declaring and initializing an object

`size_t i = 0;` gives `i` a type and an initial value. For an array, `double A[5] = {[0] = 9.0, [1] = 2.9, [4] = 3.E+25, [3] = .00007};` designates individual elements; the omitted element at index 2 is initialized to 0.0. section 2.3

How Modern C, Third Edition covers it

How deep it goes
Explains declaration forms and their distinction from definitions, while deferring pointer details and qualifying its simplified initialization rule.
Examples
Uses function and array declarations, an initialized variable, and an array with designated initializers.
What it assumes
Assumes familiarity with a small C program but introduces declaration roles before developing types and pointers further.
What you can do after
Apply it to identify what a C declaration specifies and distinguish it from an initialized object or function definition.
How it connects
Connects declarations to identifiers, types, arrays, functions, initializers, and definitions.

Also explained in

Compare how 2 books explain declaration →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.