Home > Articles

  • Print
  • + Share This
This chapter is from the book

Using typedef to Substitute a Variable’s Type

C++ allows you to substitute variable types to something that you might find convenient. You use the keyword typedef for that. Here is an example where a programmer wants to call an unsigned int a descriptive STRICTLY_POSITIVE_INTEGER.

typedef unsigned int STRICTLY_POSITIVE_INTEGER;

When compiled, the first line tells the compiler that a STRICTLY_POSITIVE_INTEGER is nothing but an unsigned int. At later stages when the compiler encounters the already defined type STRICTLY_POSITIVE_INTEGER, it substitutes it for unsigned int and continues compilation.

  • + Share This
  • 🔖 Save To Your Account