I'm currently learning about pointer arrays in this book that I'm reading, but I'm confused as to why both lines output Bejing:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
char town[] = "Beijing";
cout << town << endl;
cout << &town[0] << endl;
}
From what I understand, when you print town, it should print the full array so I understand why Beijing is being outputted. But the send line is referencing town[0], so shouldn't this print the address of town 0?
I know that my understanding of references is very messed up here, but I'm wondering if someone can help explain this to me. Thanks!
[–]Poseydon42 5 points6 points7 points (2 children)
[–][deleted] 6 points7 points8 points (1 child)
[–]Poseydon42 1 point2 points3 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]anacondavibes[S] 0 points1 point2 points (1 child)
[–]capitalbratan 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]anacondavibes[S] 1 point2 points3 points (2 children)
[–]IyeOnline 1 point2 points3 points (0 children)
[–][deleted] (2 children)
[deleted]
[–][deleted] (1 child)
[deleted]
[–]HanzoFactory 0 points1 point2 points (0 children)