the fact that u can do this means ur a pro. the only things i piucked up on was that sumtimes u sed & instead of &&, didn't have #include <iostream> and couldnt see int main(); anywhere. hope it helps!
the fact that u can do this means ur a pro. the only things i piucked up on was that sumtimes u sed & instead of &&, didn't have #include <iostream> and couldnt see int main(); anywhere. hope it helps!
& is the address operator.. most commonly used for storing a variable address into a pointer. && is the 'and' boolean expression.. use mostly for if, if/else, if/else if logical flow control.
Code:double *double_ptr; //Declare 'double_ptr' as a pointer-type variable double_ptr = &result; //Store the address of 'result' into a pointer cout << *double_ptr; //Use the '*' dereferrencing operator when you want to see what the pointer points to
vs. the && and operator
Code:if ((choice == 0) && (result > 0)) answer++;
Last edited by The Brain; 09-10-2004 at 03:37 AM.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
You don't need to prototype main.and couldnt see int main();
Quzah.
Hope is the first step on the road to disappointment.
> & is the address operator..
It is also the bitwise-AND operator, which is similar to the boolean-AND you've already mentioned.
If you writeCode:int a = 0x1234; a = a & ~0xF; // lose the bottom 4 bits = 0x1230
You wroteCode:if ( a & b )
Which is valid to do, and if a and b are boolean, you get the same answer whether you use & or &&.Code:if ( (a & b) != 0 )
The really big difference is that logical operations && and || use short-circuit evaluation, meaning the remainder of the expression is not evaluated if the result is already known.
Eg.
In case 1, foo() and bar() will both be called, and it is undefined as to which one is called first. Normal expression evaluation rules apply.Code:if ( foo() & bar() ) if ( foo() && bar() )
In case 2, foo() is always called first, and bar() is only called if foo() returned true.
This means you can test and dereference a pointer in the same expression with perfect safety.
Code:int isNonEmptyString ( char *s ) { if ( s != NULL && *s != '\0' ) return 1; else return 0; }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I belive i may have figured out why it doesnt work in 9x systems. 9x stores system files in system instead of system32, somehow I forgot to add the system part in the search, so they were looking for the files in Windows, which of course never existed . I swear i put them in, i really do. Oh Well.
However, there still is the odd thing that compiling it under XP will cause it to crash in 9x, havent tried it yet, but ill assume it hasnt changed
Maybe one of the functions you are using is implemented a different way in WinNT and the compiled code therefore is calling a non-existant function on Win9x.
As to why it would work on both platforms after being compiled on the older Win9x, WinNT needs to be compatible with older software and therefore supports the Win9x method.
Last edited by Frobozz; 09-10-2004 at 10:26 AM.
Originally Posted by Frobozz
Im gonna give up on that one, it does now work with the SYSTEM folder addition, and it also does not crash even when compiled on XP, so im just gonna consider it a fluke, since no big code was changed between my last revisions.
> if (fileExists("C:/Windows") & fileExists("C:/Winnt"))
The windows environment variable "windir" tells you the windows installation directory
Something along the lines of
Code:char *winroot = getenv( "windir" ); if ( winroot != NULL ) { } else { // start guessing, or complain }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.