 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
FirePhoenix Grandmaster Cheater
Reputation: 0
Joined: 22 Jan 2008 Posts: 575
|
Posted: Sat Feb 28, 2009 9:32 pm Post subject: C++ Question |
|
|
Sorry if this a noobie question but I'm trying to learn how to code programs in C++, and while reading the guide about Variables and Data Types the guide gives an example of what a computer does when it's processing variables. So they give this example:
a = 5;
b = 2;
a = a + 1;
result = a - b;
I understand that example, so I created my own because it gives me a sense of achievement in continuing because I understand it's a complex language. So I just want some clarification on whether my example is correct or not.
Piss = 8;
Crap = 5;
Crap = Crap - 2;
Lick = Piss + Crap;
I also have another question I don't understand how the sizes are determined for characters and integers so if someone could explain it differently than the guide that would be great.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Feb 28, 2009 10:02 pm Post subject: |
|
|
You mean how integers are 4-bytes, characters are 1-byte, and etc? Integers are meant to be able to hold all whole number values up to 4,294,967,295. 4,294,967,295 is 32-bits, or 4-bytes. Character variables are meant to hold a single character (duh lol), which only takes up 1-byte of memory.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
FirePhoenix Grandmaster Cheater
Reputation: 0
Joined: 22 Jan 2008 Posts: 575
|
Posted: Sat Feb 28, 2009 10:09 pm Post subject: |
|
|
| oib111 wrote: | | You mean how integers are 4-bytes, characters are 1-byte, and etc? Integers are meant to be able to hold all whole number values up to 4,294,967,295. 4,294,967,295 is 32-bits, or 4-bytes. Character variables are meant to hold a single character (duh lol), which only takes up 1-byte of memory. |
So it's as simple as all integers are 4 bytes and characters are 1 byte etc.? EDIT: I get it now can you help me out with declaration of variables I don't understand the need for into, bool etc.
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Sat Feb 28, 2009 10:13 pm Post subject: |
|
|
| FirePhoenix wrote: | | oib111 wrote: | | You mean how integers are 4-bytes, characters are 1-byte, and etc? Integers are meant to be able to hold all whole number values up to 4,294,967,295. 4,294,967,295 is 32-bits, or 4-bytes. Character variables are meant to hold a single character (duh lol), which only takes up 1-byte of memory. |
So its as simple as all integers are 4 bytes and characters are 1 byte etc.? |
Yes. However, don't mix integers up with doubles which are 8 bytes
_________________
|
|
| Back to top |
|
 |
FirePhoenix Grandmaster Cheater
Reputation: 0
Joined: 22 Jan 2008 Posts: 575
|
Posted: Sat Feb 28, 2009 10:22 pm Post subject: |
|
|
| kitterz wrote: | | FirePhoenix wrote: | | oib111 wrote: | | You mean how integers are 4-bytes, characters are 1-byte, and etc? Integers are meant to be able to hold all whole number values up to 4,294,967,295. 4,294,967,295 is 32-bits, or 4-bytes. Character variables are meant to hold a single character (duh lol), which only takes up 1-byte of memory. |
So its as simple as all integers are 4 bytes and characters are 1 byte etc.? |
Yes. However, don't mix integers up with doubles which are 8 bytes |
Seems easy enough, anyways I can always refer back to the chart whenever in doubt. Well now I'm having trouble with declarations of variables so to be more specific how do I know what data type to declare it (int, bool etc.) before specifying a variable identifier and so on?
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Sat Feb 28, 2009 10:32 pm Post subject: |
|
|
| FirePhoenix wrote: | | kitterz wrote: | | FirePhoenix wrote: | | oib111 wrote: | | You mean how integers are 4-bytes, characters are 1-byte, and etc? Integers are meant to be able to hold all whole number values up to 4,294,967,295. 4,294,967,295 is 32-bits, or 4-bytes. Character variables are meant to hold a single character (duh lol), which only takes up 1-byte of memory. |
So its as simple as all integers are 4 bytes and characters are 1 byte etc.? |
Yes. However, don't mix integers up with doubles which are 8 bytes |
Seems easy enough, anyways I can always refer back to the chart whenever in doubt. Well now I'm having trouble with declarations of variables so to be more specific how do I know what data type to declare it (int, bool etc.) before specifying a variable identifier and so on? |
You use whatever variable type you need for whatever you will be using it for.
For example, if you want to store the name "John Doe", you use a string, char*, etc, or whatever you want to use. (That can hold an array of characters)
Every variable type has it's own applications.
_________________
|
|
| Back to top |
|
 |
FirePhoenix Grandmaster Cheater
Reputation: 0
Joined: 22 Jan 2008 Posts: 575
|
Posted: Sat Feb 28, 2009 10:34 pm Post subject: |
|
|
| kitterz wrote: | | FirePhoenix wrote: | | kitterz wrote: | | FirePhoenix wrote: | | oib111 wrote: | | You mean how integers are 4-bytes, characters are 1-byte, and etc? Integers are meant to be able to hold all whole number values up to 4,294,967,295. 4,294,967,295 is 32-bits, or 4-bytes. Character variables are meant to hold a single character (duh lol), which only takes up 1-byte of memory. |
So its as simple as all integers are 4 bytes and characters are 1 byte etc.? |
Yes. However, don't mix integers up with doubles which are 8 bytes |
Seems easy enough, anyways I can always refer back to the chart whenever in doubt. Well now I'm having trouble with declarations of variables so to be more specific how do I know what data type to declare it (int, bool etc.) before specifying a variable identifier and so on? |
You use whatever variable type you need for whatever you will be using it for.
For example, if you want to store the name "John Doe", you use a string, char*, etc, or whatever you want to use. (That can hold an array of characters)
Every variable type has it's own applications. |
Oh I understand now so another example would be 6 so I would then use int correct?
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Sat Feb 28, 2009 10:34 pm Post subject: |
|
|
| FirePhoenix wrote: | | kitterz wrote: | | FirePhoenix wrote: | | kitterz wrote: | | FirePhoenix wrote: | | oib111 wrote: | | You mean how integers are 4-bytes, characters are 1-byte, and etc? Integers are meant to be able to hold all whole number values up to 4,294,967,295. 4,294,967,295 is 32-bits, or 4-bytes. Character variables are meant to hold a single character (duh lol), which only takes up 1-byte of memory. |
So its as simple as all integers are 4 bytes and characters are 1 byte etc.? |
Yes. However, don't mix integers up with doubles which are 8 bytes |
Seems easy enough, anyways I can always refer back to the chart whenever in doubt. Well now I'm having trouble with declarations of variables so to be more specific how do I know what data type to declare it (int, bool etc.) before specifying a variable identifier and so on? |
You use whatever variable type you need for whatever you will be using it for.
For example, if you want to store the name "John Doe", you use a string, char*, etc, or whatever you want to use. (That can hold an array of characters)
Every variable type has it's own applications. |
Oh I understand now so another example would be 6 so I would then use int correct? |
Yes.
_________________
|
|
| Back to top |
|
 |
FirePhoenix Grandmaster Cheater
Reputation: 0
Joined: 22 Jan 2008 Posts: 575
|
Posted: Sat Feb 28, 2009 10:36 pm Post subject: |
|
|
| Ok now what would be a example for bool and float? Btw thanks for sticking around with me I know I'm a noob but I appropriate your help a lot thanks.
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Sat Feb 28, 2009 10:49 pm Post subject: |
|
|
| FirePhoenix wrote: | | Ok now what would be a example for bool and float? Btw thanks for sticking around with me I know I'm a noob but I appropriate your help a lot thanks. |
a float is a decimal number. Like say you want to store the amount of money John Does has.
| Code: | | float DoesMoney = 500000.77; |
A Bool, or Boolean is either a "Yes" or "No" value. (1 or 0).
This is used for returns of many functions, to indicate weither it was successful or not. (if returns true, the function succeeded, if false, it failed) There are many applications for this. Another example could be....is John Does married or not?
| Code: | | bool Married = false; |
_________________
|
|
| Back to top |
|
 |
FirePhoenix Grandmaster Cheater
Reputation: 0
Joined: 22 Jan 2008 Posts: 575
|
Posted: Sat Feb 28, 2009 10:56 pm Post subject: |
|
|
| kitterz wrote: | | FirePhoenix wrote: | | Ok now what would be a example for bool and float? Btw thanks for sticking around with me I know I'm a noob but I appropriate your help a lot thanks. |
a float is a decimal number. Like say you want to store the amount of money John Does has.
| Code: | | float DoesMoney = 500000.77; |
A Bool, or Boolean is either a "Yes" or "No" value. (1 or 0).
This is used for returns of many functions, to indicate weither it was successful or not. (if returns true, the function succeeded, if false, it failed) There are many applications for this. Another example could be....is John Does married or not?
| Code: | | bool Married = false; |
|
Ok I see, thanks I'll try to get through the first section and post problems I may get later instead of bugging you every 5 minutes, thanks a lot though.
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sat Feb 28, 2009 11:39 pm Post subject: |
|
|
Finally, someone learning programming the RIGHT way. If you're having a lot of little questions, you can also hop on IRC and they'll probably help you out.
_________________
|
|
| Back to top |
|
 |
`unknown Grandmaster Cheater
Reputation: 0
Joined: 20 Nov 2006 Posts: 658 Location: You lost the game.
|
Posted: Sun Mar 01, 2009 1:13 am Post subject: |
|
|
Also note that some data types have limits, such as all assortments of int's (±2^15-1 for signed short, +2^16-1 for unsigned, etc.) Keep that in mind when selecting a data type.
Edit: Oh and don't forget you can include operations in your assignment code like this (using your example, but re-written):
| Code: | Crap -= 2; // same as Crap = Crap - 2
Crap += 2; // same as Crap = Crap +2
Crap *= 2; // i think you get the idea :] |
|
|
| Back to top |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Sun Mar 01, 2009 2:22 am Post subject: |
|
|
everything in C/c++ starts from a byte unsigned I believe which can hold only 0 as the lowest number and 255 as the highest now if you sign it.. aka
signed byte test;
now it will hold half the highest value 127.. but now you have the ability to hold below the lowest number of 0.. which will be now -127 (negative) and 0 as well..
now the other datatypes WORD/DWORD/QWORD aka short/int/long
are just like that byte.. but word is 2 bytes dword is WORD doubled.. thats what the d means.. so double the word is 4 bytes and qword is quadruple the word which means 8 bytes of course
now a byte is just a bunch of switches which work similar to booleans.. (bool datatype in c/c++) which can only hold 1 or 0 and in most cases the 1 is called TRUE and 0 is called FALSE.
now how is a byte a bunch of booleans? well it is.. if you keep thinking about it.. a byte is a series of doublers.. and a doubler of bytes is the same process but on a macro level.. now if you think on a lower level the micro level the doublers work like this..
starts from the smallest number possible well not 0.. but 1 and keeps doubling
1 2 4 8 16 32 64 128 256
there you go..
now a byte is also called 8 bits what are bits? thats what makes up bytes and those are the doublers which can create any number from 0 to 255 unsigned.
like lets say
1 2 4 8 16 32 64 128
are a bunch of on/off switches (transistors/some kind of memory cell)
now lets make em all 0's (off/FALSE)
1 2 4 8 16 32 64 128
0 0 0 0 0 0 0 0
say
101011 now lets see what it means..
1+4+16+32 = 53
yup and 101011 is binary for the number 53 in byte mode.
and of course if you add em all on
11111111
1+2+4+8+16+32+64+128 = 255 (max value for byte)
now double bytes aka WORD aka SHORT has a value of 2 bytes
so if you keep doing the combination..
1+2+4+8+16+32+64+128 (repeat it 8 more times since a byte is 8 bits)
1+2+4+8+16+32+64+128+256+512+1024+2048+4096+8192+16384+32768
also notice how signed byte max value is the final bit? 128..
also notice how signed word (short) max value is also final bit.. 32768
and of course if you add up
256+512+1024+2048+4096+8192+16384+32768 = 65,535 (unless i screwed up).
anyways you have to learn all these basics and hardcode them into your mind if you want to get anywhere in programming in your life.
just changing these numbers around made mostly everything in programming we know today.
_________________
|
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Sun Mar 01, 2009 2:31 pm Post subject: |
|
|
Actually, everything starts off as signed. That means that the last bit is the signed bit.
If it is a 1, then it is negative. If it is a 0, it is positive.
| Code: |
00000000 = Positive
10000000 = Negative |
With that bit used to determine the sign, we only have 7 bits to deal with.
| Code: |
1 byte
Max:
01111111 = 127
Min:
10000000 = -128
|
To get the negative representation, we have to invert the bits and add 1 since it's using 2's compliment.
| Code: |
10000000 = -128
01111111->invert = 127
10000000->add 1 = 128
|
You could also use the equation N* = 2^n - N
n = number of bits
N = number
Let's use this equation to verify the top
| Code: |
n = 8 bits
N = 128
2^8 = 256
256- 128 = 128
128 = 10000000
10000000 = 10000000
|
When it's unsigned, that means it will be all positive numbers.
| Code: | 00000000 = 0
11111111 = 255 |
This is because the last bit is no longer used to determine the sign. This is how all the data types work.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|