I was writing a small program to work with pointers and came across strange compiler behavior.
First case:
#include <iostream>
#include <typeinfo>
int main(int argc, char** argv)
{
int* a,b;
std::cout << typeid(&a).name() << std::endl;
std::cout << typeid(&b).name() << std::endl;
return 0;
}
In the first case, the program output will be like this:
PPi
Pi
Which, as far as I understand, means that a pointer to “a” will be of type “int**”, while a pointer to “b” will be of type “int*”
This seems strange to me and I can’t understand why it works this way.
Second case:
#include <iostream>
#include <typeinfo>
int main(int argc, char** argv)
{
int* a;
int* b;
std::cout << typeid(&a).name() << std::endl;
std::cout << typeid(&b).name() << std::endl;
return 0;
}
Second output:
PPi
PPi
And in this case, pointers receive the types that, in theory, should have received in the first case.
I have no idea where to look for information about this. There was nothing about this in the book I learned C++ from.
s0nny13 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1