Close
Close

Practice questions on Pointers

Level 1

1.
Write a program to print the address of a variable whose value is input from user.
#include<iostream>
using namespace std;

int main()
{
    int x;
    cout << "Enter a number\n";
    cin >> x;
    cout << "Address is "<<&x<<"\n";
    return 0;
}									

2.
Write a program to print the address of the pointer to a variable whose value is input from user.

3.
Write a program to print the value of the address of the pointer to a variable whose value is input from user.
#include<iostream>
using namespace std;

int main()
{
    int x, *y;
    cout << "Enter a number\n";
    cin >> x;
    y = &x;
    cout << "Value of the address of pointer of "<< x << " is "<< &y<<"\n";
    return 0;
}									

4.
Write a program to print a number which is entered from keyboard using pointer.
#include<iostream>
using namespace std;

int main()
{
    int x;
    cout << "Enter a number\n";
    cin >> x;
    cout << *(&x) << "\n";
    return 0;
}									

5.
Write a function which will take pointer and display the number on screen. Take number from user and print it on screen using that function.
#include<iostream>
using namespace std;

void print(int *a)
{
    cout << *a << "\n";
}

int main()
{
    int x;
    cout << "Enter a number\n";
    cin >> x;
    print(&x);
    return 0;
}									

6.
Write a program to find out the greatest and the smallest among three numbers using pointers.

Level 2

1.
Write a program to find the factorial of a number using pointers.

2.
Write a program to reverse the digits a number using pointers.

Level 3

Ask Yours
Post Yours