Alias For a Data Type

◀ C++ Escape Sequence Codes▶ Check Value Inputted by User
Amazon Building an alias for a data type makes life simpler because it allows you to use a complicated data type via a short hand way.

There are two ways to establish an alias for a type. One is to use #define and the other is to use typedef. For example, to make byte an alias for char, we do the following:
#define byte char
or
typedef char byte;
We can make an alias for a pointer, too. For example, if we want to make bytePointer an alias for char*, we can do the following:
#define bytePointer char*
or
typedef char* bytePointer;
There is a danger in using #define. For example, consider the following:
#define bytePointer char*
bytePointer bp, bp2;
Preprocessor replaces bytePointer with char*, converting the above declaration to be
char* bp, bp2;
Only bp is a pointer to char; bp2 is a char. However, typedef will treat both bp and bp2 as pointers to char.

Next let’s look at how to make sure user enters the type of data you want them to enter!
◀ C++ Escape Sequence Codes▶ Check Value Inputted by User

fShare
Questions? Let me know!