|
| kaustubh (1) | |
| 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.. | |
| giantMidget (14) | |
| Post your code and any errors. | |
| Bazzy (4106) | |
| 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*/]; | |
| helios (6052) | |
| 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. | |
| Bazzy (4106) | |||
Are you shure? I've tryed this code both on VC++ and MingW and it works
output: 99 6 | |||
Last edited on | |||
| helios (6052) | |
Oh, well int (&ref_to_array)[5]=arr; is different from int (&ref_to_array)[5];. | |
| Bazzy (4106) | |
| I think that references are useful only as function arguments, in other cases pointers are best | |
This topic is archived - New replies not allowed.
