Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Programming Fundamentals/Typedef - An Alias

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

An explanation of typedef being used to create an alias data type. General Discussion The typedef statement allows the programmer to create an alias, or synonym, for an existing data type. This can be useful in documenting a program. The C++ programming language syntax is: typedef <the real data type> <the alias identifier name>; Let's say a programmer is using a double data type to store the amount of money that is being used for various purposes in a program. He might define the variables as follows: Example 1: Regular Definition of Variables double income; double rent; double vacation; However, he might use the typedef statement and define the variables as follows: Example 2: Using typedef when Defining Variables typedef double cash; the typedef must be defined before its use cash income; cash rent; cash vacation; The typedef statement is not used very often by beginning programmers. It usually creates more confusion than needed, thus stick to using the normal data types at first. Definitions typedef Allows the programmer to create an alias, or synonym, for an existing data type.