Declaring a pointer, int *ptr vs int ptr
The following code works
Code:
#include <iostream>
using namespace std;
int main()
{
int a = 1;
int *b;
b = &a;
cout << " a is:" << a << endl;
cout << " &a is:" << &a << endl;
cout << " b is:" << b << endl;
cout << " *b is:" << *b << endl;
return 0;
}
If I change "int *b" to "int b," as shown below, then the code does not compile. Why is this? What exactly does the statement "int *b declare?"
Code:
#include <iostream>
using namespace std;
int main()
{
int a = 1;
int b;
b = &a;
cout << " a is:" << a << endl;
cout << " &a is:" << &a << endl;
cout << " b is:" << b << endl;
cout << " *b is:" << *b << endl;
return 0;
}