Declarations O_O ????????

Posts 17 of 7 · Page 1 of 1
Declarations O_O ????????
Okay, my had has been spinning on how to declare each specific so can someone help me out here? I can't find an eBook on it and can't afford an actual book. =(

I know the following...

*(int*) ( RandomThing ) = 7;
*(float*) ( RandomThing2 ) = 0.0f
*(long*) ( RandomThing3 ) = 9999999;
*(double*) ( RandomThing4 ) = 4113;
*(bool*) ( RandomThing5 ) = true;

Correct any if wrong, and please post any further ones. Specifically strings at the moment, I really am having a hard time with string declaration. =( Also, can someone give me some quick definitions on the following things.

#include
#define
void
public
private
float
double
long
bool
for
return

I would really appreciate a short definition of each of those with a quick example on how to use them. ( I know some of the basics about these items I just want to know more is all. =P Knowledge is epic.)

Also, if anyone could tell me how to close one form, and open another in Visual Studio 2010 Proffessional C++ it would be greatly appreciated. Much thanks to whoever can help me out.
As you are using pointers to things instead of common declarations for variable declaration, I think you would need to review your basis on this language ; Sure thing e-Books can be hard to find but they are worth it, And if you can't find one ; Websites like "cplusplus.com", And such offer some interesting basic courses and stuff ; Worth to take a look, They should cover declaration .

My tip : Don't look for tutorials, Look for courses, Elaborated ones, There should be a few ones available for free or at least on our Torrenty websites.
epic declaring variables. Seems just like a declaration in a PTC function.

#include - isnt it obvious?
#define - isnt it obvious?
void - no return type
public - your class can access it directly
private - your class cant use it directly
float - in your post you declared a float. Lolwut
double - same as above, just with double
long - same as above, just with long
bool - same as above, just with bool
for - for each
return - what a function returns.

so many contradictions tsk tsk
Anything starting with '#' is a preprocessor directive.
#include "blah.h" will basically perform a copy/paste of blah.h where that line is (Hence 'include guards' are needed)

#define is used for macros. A way to get the preprocessor to write code for you.
I use this for my long list of 'script command' handler function declarations
[php]#define SC_DECL( x ) void x( const char *args )
SC_DECL( OpenMenu );
SC_DECL( CloseMenu );
SC_DECL( PlaySound );
SC_DECL( ExitGame );
#undef SC_DECL[/php]
Output is
[php]void OpenMenu( const char *args );
void CloseMenu( const char *args );
void PlaySound( const char *args );
void ExitGame( const char *args );[/php]

Then there are the 'base types' for declaring variables, functions, etc.

bool = C++ keyword. The value can only be 'true' or 'false'. Size is 1 bit. (Unless it's stored as a byte - I'm unsure, but probably is)
int = C/C++ keyword. An integer, WORD size of the machine (assumed 32 bits). Numbers like -10, -4, 0, 1, 2, 3, 223
long = C/C++ keyword. At-least 32 bits(?), same values as int
float = C/C++ keyword. Floating point number with single-precision. Numbers like 0.3f, 0.345345f, 3.14159265f.
double = C/C++ keyword. Floating point number with double-precision. Same values as above, but more precise.
char = C/C++ keyword. A single character, treated as a number between -127<->127 or 0<->255 depending on signed/unsigned. A "string" is a sequence of characters terminated by 0 (So the program knows where a string ends, otherwise it'd read on forever through memory)
void = C/C++ keyword. Used for pointers with no logical type, and functions that don't have a return value. It can't hold a value (Aside from a pointer)
It's important to learn the sizes of each variable type. Google/Wiki this

signed/unsigned - Tells whether the number can be negative or not.
For a signed variable, the MSB (Most-significant-bit, machine dependent) controls whether the number is treated as negative or not. Wiki this.

return - Used in a function to stop execution of that function. Useful for error handling.

for - A keyword used for looping.
syntax:
[php]for ( initialisation; condition; statement )
{
body
}[/php]
Order of execution:
  • initialisation
  • condition
  • if condition was met, body. otherwise, end loop
  • statement
  • condition
  • if condition was met, body. otherwise, end loop


[php]int i;
for ( i=0; i<10; i++ )
{
//Do this until i == 10, incrementing i each loop
}[/php]


-- too lazy to continue
There are free online tuts that teach basics. If you dont know about declaration, by all means you should not use pointers.
Thank you razor, you helped a lot. I wanted to confirm each and make sure I knew what each is doing in c++. I know about declarations I'm not a complete idiot, but finding eBooks is hard sometimes. Especially with the information you really want. I start college in January so I'm not too worried about it. I was just checking to make sure I had a correct understanding of each. Razor you answered my questions successfully and much thanks to you for that. =)
Information you want?

Learn the entire language.
Posts 17 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?