Thursday, March 2, 2017

Getting good at: C++ | #10 - enumerated constants, integers and more typedef

10 - typedef int our; our number = 1;

     Hows it goin bros, coat hanger here. Today, we're going to use typedef. As I said in the last post, typedef is used to substitute keywords in integers. "How is this useful?", you ask. To show you why, I will have to go over another integer type, the unsigned integer.

     Now, an unsigned integer is basically a whole number integer, meaning it cannot store a negative value. Along with that, there is the long integer and the short integer. A long integer can store values from -2 billion to 2 billion, and a short integer can store values from -32768 to 32767. All of the possible integer types can be found here. Now, if you were writing a program that uses a lot of unsigned long integers, you would probably get tired of writing unsigned long number = 32000;, and that's where ya boi typedef comes in. So instead of typing unsigned long number 32000;, you can just type something like ulo number 32000;

     Last post, I talked about constants, read-only variables. Now, I'm going to talk about enumerated constants. This is basically a way to store multiple constants on one line. To declare it, you have to write something like this: enum name { N=1, A=3, M=5, E=8 };. If you don't set the variables to anything, then the beginning variable is set to zero, and the variable to the right of it is the left + 1.

That's all I have for this post. 

No comments:

Post a Comment