Author Topic: typedef  (Read 720 times)

Offline beingchinmayTopic starter

  • Trade Count: (0)
  • Jr. Member
  • **
  • Thank You 1
  • Posts: 73
  • Karma: 0
  • Gender: Male
  • I am Chinmay
    • Modular Kitchen Designer
« on: 09-16-2016, 06:36:40 »
C++ allows you to define new data type names with the typedef keyword. When you use typedef, you actually are not creating a new data type, but rather are defining a new name for an existing type. This process can help make machine-dependent programs more portable; only the typedef statements have to be changed. It also can help you self-document your code by allowing descriptive names for the standard data types. The general form of the typedef statement is

typedef type new-name;

where type is any valid data type, and new-name is the new name for this type. The new name you define is in addition to, not a replacement for, the existing type name.

For example, you could create a new name for float using

typedef float balance;

This statement would tell the compiler to recognize balance as another name for float. Next, you could create a float variable using balance:

balance over_due;

Here, over_due is a floating-point variable of type balance, which is another name for float