am i correct

closed account (9G3v5Di1)
Write a program that will display the value and logical address of an uninitialized float array with size twenty (20) and a reference pointing to the array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  #include <iostream>
#include "_pause.h"

using namespace std;

int main(){
  float n[20];

  float &ref = n[20];
  float *ptr = &n[20];

  cout << "The value is " << ref << endl;
  cout << "The address is " << ptr << endl;
  cout << endl;

  _pause();
  return 0;
}


The value is 8.99955e-039
The address is 0x61ff18

Press any key to continue. . .
Last edited on
A few points.

Don't use
using namespace std;
it is a bad habit I myself have.

Use double instead of float. Double is better.

cout << endl;
Is a waste of a line.

In your code, ref is a reference to the 21st element of your array n - i.e. something that doesn't exist.

Similarly, ptr is a pointer to the 21st element of your array n - i.e. something that doesn't exist.

Topic archived. No new replies allowed.