Question: If you want to declare a pointer variable, then which operator will be used?
(A). * before the variable name
(B). * After the variable name
(C). – before the variable name
(D). – after the variable name
Correct Answer: (A). * before the variable name
Example of the Program in C
*x and *y are two pointer variables having * before the variable name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <stdio.h> int main() { int num1, num2, *x, *y, sum; printf("Enter two integers to add\n"); scanf("%d%d", &num1, &num2); x = &num1; y= &num2;
sum = *x + *y; printf("The Sum of the numbers = %d\n", sum); return 0; } |
Output
Enter two integers to add
6
7
The Sume of the numbers = 13
Example of the Program in C++
*pointer_1 and *pointer_2 are two pointer variables having * before the variable name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <iostream> using namespace std; int main() { int num1, num2; int *pointer_1,* pointer_2; int sum; cout<<" Please Enter the first number: "<<endl; cin>>num1; cout<<" Please Enter the second number: "<<endl; cin>>num2; pointer_1 = &num1; //assigning an address to pointer pointer_2 = &num2; sum = *pointer_1 + * pointer_2; //values at address stored by pointer cout<<"The Sum is: "<< sum<<endl; return 0; } |
Output
Please Enter the first number:
3
Please Enter the second number:
4
The sum is: 7
Highly Recommended C++ Important MCQs with Explanation
- Which symbol is used to create multiple inheritances?
- If a derived class object is created, which constructor is called first?
- Which of the following is not a type of constructor?
- a ____ is a member function that is automatically called when a class object is __.
- What is the output of the following code in C++?
- How many times will the following code print?
- Which of the following is a procedural language?
- Which of the following is not a programming language?
- Which of the following is not an example of high-level language?
- While declaring pointer variables which operator do we use?
- To which does the function pointer point to?