The address of a variable returned by the reference operator (&) is not an l-value, meaning you can't put it on the left side of an assignment operator. Besides, why would you want to?
int x;
x = *(new int[5]);
(&x)[0] = 1;
(&x)[1] = 1337;
but I believe this is a very bad idea. new is creating an array of five ints, and this array is being copied into x, leaving the original array somewhere in memory that is unknown to us, so we can't delete it later. Also, x only has room for one int, not 5, so copying 5 ints into x may intrude on memory belonging to someone else.
Hmm I guess I was just trying to continue as I had been before i.e int* a; a=&b; Then using b unless I want to send it into a function or something but I guess this doesn't carry over in this case.
Just to check I have got the right end of the stick, you are saying it is best to just define a pointer and continually dereference it every time? There is no "normal" variable defined at the memory address of the pointer.
Hmm I guess I was just trying to continue as I had been before i.e int* a; a=&b; Then using b unless I want to send it into a function or something but I guess this doesn't carry over in this case.
I'm not following exactly...
a contains the address of b. modifying b is the same as modifying *a, until a is resigned to another address, or b goes out of scope (or a goes out of scope)Just to check I have got the right end of the stick, you are saying it is best to just define a pointer and continually dereference it every time? There is no "normal" variable defined at the memory address of the pointer.
I'm not sure what you mean by "normal variable". Do you mean a primitive data type (i.e., int, float, double, char, short, long, etc.)? If so, there can definitely be a normal variable at the address of a pointer:
int* x = new int;//there is an int at the memory address of int
*x = 5;
//work with x, even past ends of scope
delete x;//you need to manually free the int, C++ won't do it for you when you use new
the value that x itself contains is a a memory address. you should only use x without the dereference operator if you're dealing with another pointer
int y = new int;
*y = 6;
delete x;//assuming x wasn't already deleted
x = y;//no dereference
I know the basics of working with int, float and structures but I am not as good with pointers I know how to do an array of structures for examples if the structure was called records i would normally do something like records[i].title for example. Since I dynamically allocated the memory I am struggling since I had to define a pointer to a structure and I can't figure out how to do the equivalent i've tried things like (*records[i]).title and records[i]->title.