Clarification Needed!!

Posts 1–7 of 7 · Page 1 of 1
Clarification Needed!!
So I'm on variables now on my quest to learning the basics of cpp.

I need clarification on the types of variables and data types there are.

For example,

what kind of case would need a floating integer?

It just doesn't click in my head.
Err? Rephrase that question..i'm not sure what you mean.

All integer types come in two varieties: signed and unsigned. The idea here is that sometimes you need negative numbers, and sometimes you don't. Integers (short and long) without the word "unsigned" are assumed to be signed. Signed integers are either negative or positive. Unsigned integers are always positive.

Because you have the same number of bytes for both signed and unsigned integers, the largest number you can store in an unsigned integer is twice as big as the largest positive number you can store in a signed integer. An unsigned short integer can handle numbers from 0 to 65,535. Half the numbers represented by a signed short are negative, thus a signed short can only represent numbers from -32,768 to 32,767.

Several other variable types are built into C++. They can be conveniently divided into integer variables (the type discussed so far), floating-point variables, and character variables.
Floating-point variables have values that can be expressed as fractions--that is, they are real numbers. Character variables hold a single byte and are used for holding the 256 characters and symbols of the ASCII and extended ASCII character sets.


__________________________________________________ ________
Format:
[VariableType] == [Size (may vary)] == [what number it can go down/up to]

unsigned short int == 2 bytes == 0 to 65,535
short int == 2 bytes == -32,768 to 32,767
unsigned long int == 4 bytes == 0 to 4,294,967,295
long int == 4 bytes == -2,147,483,648 to 2,147,483,647
int (16 bit) == 2 bytes == -32,768 to 32,767
int (32 bit) == 4 bytes == -2,147,483,648 to 2,147,483,647
unsigned int (16 bit) == 2 bytes == 0 to 65,535
unsigned int (32 bit) == 2 bytes == 0 to 4,294,967,295
char == 1 byte == 256 character values
float == 4 bytes == 1.2e-38 to 3.4e38
double == 8 bytes == 2.2e-308 to 1.8e308
Mkay, clearer now...

But the 2 main things that I still don't understand what floats are and doubles.
Variables. Data Types.ⓘ
Hopefully that makes it a little bit clearer. If not PM me and ill try to help you. I don't really understand what you can't understand.
It's not that often that I use floats and doubles. Generally such accurancy isn't commonly required. You'll need it to perform some operations, but generally you'll be working with int, long, and(rarely) short. It's better you make your code clear and neat. The optimizer can worry about optimization.

Also, one common mistake beginners make is the avoiding of the standard C++ library. You should be making constant use of string, and stringstream objects, or vectors(over arrays. Arrays really should be avoided if possible unless you have a _good_ reason for using them). Avoid pass-by-pointer. You should pass-by-reference when possible.

I.e, don't go
void someOperation(std::string* pString);

It should be
void someOperation(std::string& sString);

Avoid creating global variables that aren't going to be exported for other source files to use. Even at that, if your functions rely upon global variables, then it should all be thrown into a class.

Fasdf, I could go on and on, maybe I'll make a thread. A lot of these mistakes are made here quite a bit.
Quote Originally Posted by radnomguywfq3 View Post
Fasdf, I could go on and on, maybe I'll make a thread. A lot of these mistakes are made here quite a bit.
/gogogo
also he didn't int main ()
That would be awsome jetamay
Posts 1–7 of 7 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us