Skip to content

Latest commit

 

History

History
67 lines (56 loc) · 3.03 KB

CppDeclaration.md

File metadata and controls

67 lines (56 loc) · 3.03 KB

'A declaration introduces a name into a program' [1].

'A declaration of a variable or function announces the properties of the variable or function; it consists of a type name and then the variable or function name. For functions, it tells the compiler the name, return type and parameters. For variables, it tells the compiler the name and type.' [3]

There are multiple types of declarations:

  1. A variable declaration is naming a variable to be used.
  2. A function declaration is naming a function to be defined.

Example

In the code below, the function MagicFunction and the integer x are declared.

void MagicFunction();  

int main() 
{   
  int x;  
}
  1. John Lakos. Large-Scale C++ Software Design. 1996. ISBN: 0-201-63362-0. Chapter 1.1.1
  2. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 6.6. Advice. page 169: '[11] Declare one name (only) per declaration'
  3. Joint Strike Fighter Air Vehicle C++ Coding Standards for the System Development and Demonstration Program. Document Number 2RDU00001 Rev C. December 2005. 4.3.13: 'A declaration of a variable or function announces the properties of the variable or function; it consists of a type name and then the variable or function name. For functions, it tells the compiler the name, return type and parameters. For variables, it tells the compiler the name and type'
  4. Paul Deitel, Harvey Deitel. C++11 for progrgrammers (2nd edition). 2014. ISBN: 978-0-13-343985-4. Chapter 2.4, Good Programming Practice 2.3. page 26: 'Declare only one variable in each declaration and provide a comment that explains the variable's purpose in the program.'
  5. Gottschling, Peter. Discovering Modern C++: An Intensive Course for Scientists, Engineers, and Programmers. Addison-Wesley Professional, 2015. Chapter 1.2: 'Declare variables as late as possible, usually right before using them the first time and whenever possible not before you can initialize them'