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.

The declaration `int main(int, char*[]);` tells the compiler that `main` is a function returning `int`. Its parameters have the types shown in the parentheses; the declaration does not supply a function body. section 2.2 section 2.3

A declaration specifies what an identifier represents and associates properties with it. Identifiers must be declared before use; keywords, by contrast, are predefined and must not be declared or redefined. section 2.2

The form of a declaration gives clues to the identifier’s role:

  • `int argc;` declares `argc` with type `int`. section 2.2
  • `double A[5];` declares `A` as an array of five `double` elements, indexed from 0 through 4. section 2.2
  • `[[maybe_unused]] char* argv[];` includes an attribute indicating that `argv` is possibly unused. The `*` indicates a pointer type. section 2.2

A declaration does not necessarily supply an object’s concrete value or storage. A definition fills that role, and a declaration can also be a definition. For example, `size_t i = 0;` declares `i`, initializes it to zero, and defines the object by providing storage for its value. section 2.3 section 2.3

For a function, a declaration followed by a body in braces is a definition. TAKEAWAY: declarations specify identifiers; definitions specify objects or supply function bodies. section 2.3

How Modern C, Third Edition covers it

How deep it goes
Explains declaration forms and their relationship to definitions, while deferring detailed pointer treatment.
Examples
Uses declarations of `main`, `argc`, `argv`, and `A`, plus an initialized `size_t i`.
What you can do after
Evaluate and understand whether an example declaration also defines an initialized object or a function body.
How it connects
Connects declarations to types, arrays, functions, definitions, and initialization.

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.