Tuesday, May 26, 2009

C++ keyword: typedef

This is something I neglected to mention in my little spiel on how variables work.

The C++ keyword "typedef" allows you to declare your own type of variable. For example, if you wanted all unsigned short ints to be called USHORT you would write:

typedef unsigned short int USHORT;

Then you could more easily declare unsigned short ints by just typing USHORT like such:

USHORT anewvariable = 5;

So the whole thing would go together like this:

typedef unsigned short int USHORT;

USHORT anewvariable = 5;
USHORT anothernewvariable = 15;

Hope that clears things up on why you'll see variable types that I didn't mention before. It's because programmers (like yourself) made their own variable types!

No comments:

Post a Comment