declaration problems

Hi folks, i have a bit of trouble with the following declarations
1. a pointer to an array of strings
2. a reference to an array of integers
Any help will be appreciated..
Post your code and any errors.
A pointer to an array is a pointer to the first element of that array.
For a reference to an array just parenthesise
eg:
int (&ref_to_array)[/*Array size*/];
Nope. There's no such thing as a reference to an array of integers. A reference can only point to a single variable or object, and due to their syntax, the offset operator can't be applied to them.
I can't even get a reference to a pointer to work. Man, references suck.
Are you shure? I've tryed this code both on VC++ and MingW and it works
1
2
3
4
5
6
7
8
int arr[5] = {1,2,3,4,5};
int (&ref_to_array)[5]=arr;
ref_to_array[2] = 99;

int numb=6, *pointer, *&ref_to_pointer=pointer;
ref_to_pointer = &numb;

cout << arr[2] << ' ' << *pointer;

output: 99 6
Last edited on
Oh, well int (&ref_to_array)[5]=arr; is different from int (&ref_to_array)[5];.
I think that references are useful only as function arguments, in other cases pointers are best
Topic archived. No new replies allowed.