Skip to main content

pointers-strings

1).What is the correct syntax to declare a pointer in C++?

1) int* ptr;
2) pointer int ptr;
3) ptr int*;
4) None of the above

2).Which of the following is used to access the value at the pointer address in C++?

1) *
2) &
3) #
4) %

3).What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
int x = 10;
int* ptr = &x;
cout << *ptr;
return 0;
}
1) 10
2) x
3) ptr
4) Error

4).What is the correct way to declare a reference in C++?

1) int& ref;
2) reference int ref;
3) ref int&;
4) None of the above

5).Which operator is used to obtain the address of a variable in C++?

1) *
2) &
3) @
4) #

6).What is the purpose of the `nullptr` keyword in C++?

1) It is used to initialize a pointer to null
2) It is used to delete a pointer
3) It is used to declare a reference
4) None of the above

7).What will happen if you dereference a null pointer in C++?

1) The program will terminate
2) The value will be 0
3) It will return an error
4) Nothing will happen

8).Which of the following functions is used to get the size of a pointer in C++?

1) sizeof()
2) length()
3) size()
4) None of the above

9).What is the difference between a pointer and a reference in C++?

1) A reference must be initialized at declaration, a pointer can be null
2) A pointer cannot be null, a reference can be
3) A pointer is always constant, a reference is not
4) None of the above

10).What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
int x = 10;
int& ref = x;
ref = 20;
cout << x;
return 0;
}
1) 10
2) 20
3) Error
4) None of the above