C++ Program to print address of a number
Simple C Program to print address of a number: To print address any number, we use & sign. For example if we want to print address number n=9, then we will &n.
Another C++ program to print address using pointer
Pointer is a variable that store address of another variable. For example we want to print address of n then we will declare a pointer to integer *ptr and initialize it as ptr=&n and then pointer ptr will print address of n.
If you want to print address of a floating point number or double number then you have to declare a pointer to float or pointer to double.
/* C++ Program to print address of number */ #include<iostream> using namespace std; int main() { int n; cout<<"Enter a number: "; cin>>n; cout<<"Address of number "<<n<<" = "<<&n; return 0; }
Another C++ program to print address using pointer
Pointer is a variable that store address of another variable. For example we want to print address of n then we will declare a pointer to integer *ptr and initialize it as ptr=&n and then pointer ptr will print address of n.
/* C++ Program to print address of number */ #include<iostream> using namespace std; int main() { int n,*ptr; cout<<"Enter a number: "; cin>>n; ptr=&n; cout<<"Address of number "<<ptr<<endl; cout<<"Address of number "<<&n<<endl; return 0; }
If you want to print address of a floating point number or double number then you have to declare a pointer to float or pointer to double.