I'd like to make one variable always equal to 1/3rd of another variable. I've tried the following...
But I get "error C2296: '/' : illegal, left operand has type 'int *'"Code:int x; int *p; p = &x/3;
How do I get this to work? Thanks in advance
I'd like to make one variable always equal to 1/3rd of another variable. I've tried the following...
But I get "error C2296: '/' : illegal, left operand has type 'int *'"Code:int x; int *p; p = &x/3;
How do I get this to work? Thanks in advance
Thats not the way pointers work, they store memory addresses,
not actually the data. The code you posted attempts to divide
the physical memory address of the variable x by 3, and assign
it to the pointer p. Obviously that won't do so here's what you
want:
if you dont understand that then suggest reading up a bit onCode:int x = 3; int *p; p = &x; cout <<"x/3 is equal to: "<<*p/3;
pointers, i found them tricky until i actually took a minute to
sit down with them and i found that they're not too bad at all.
No No's:
fflush (stdin); gets (); void main ();
Goodies:
Example of fgets (); The FAQ, C/C++ Reference
My Gear:
OS - Windows XP
IDE - MS Visual C++ 2008 Express Edition
ASCII stupid question, get a stupid ANSI
To see why your code doesn't work, try this:
Code:int x = 20; cout<<&x<<endl;