Q.

What will be the output of the following C++ code ?

#include <iostream> 
using namespace std; 
int main() { 
int numbers[5]; 
int *p; p = numbers; 
*p = 10; p++; 
*p = 20; 
p = numbers[2]; *p = 30;
p = numbers + 3; 
*p = 40; p = numbers; *(p + 4) = 50; 
for (int n = 0; n < 5; n++)
{ 
   cout << numbers[n] << ","; } return 0; 
  }
A.  

10,20,30,40,50,

B.  

1020304050

C.  

compile error

D.  

runtime error

Similar Questions
1.

Which of the following is the proper declaration of a pointer ?

A.  

int x;

B.  

int &x;

C.  

ptr x;

D.  

 int *x;

2.

Which of the following gives the memory address of integer variable a ?

A.  

*a;

B.  

 a;

C.  

&a;

D.  

address(a);

3.

Which of the following gives the memory address of a pointer a ? 

A.  

a;

B.  

*a;

C.  

&a;

D.  

address(a)

4.

Which of the following gives the value stored at the address pointed to by the pointer a ?

A.  

a

B.  

val(a);

C.  

*a;

D.  

&a

5.

Which of the following is the proper keyword to allocate memory ?

A.  

new

B.  

malloc

C.  

create

D.  

value

6.

Which of the following is the proper keyword to deallocate memory ?

A.  

free

B.  

delete

C.  

clear

D.  

remove

7.

What does the following statement mean ?

A.  

pointer to a pointer

B.  

pointer to an array of chars

C.  

pointer to function taking a char* argument and returns an int

D.  

function taking a char* argument and returning a pointer to int

8.

The operator used for dereferencing or indirection is ____

A.  

*

B.  

&

C.  

->

D.  

–>>

9.

Choose the right option.
string* x, y;

A.  

x is a pointer to a string, y is a string

B.  

y is a pointer to a string, x is a string

C.  

both x and y are pointers to string types

D.  

y is a pointer to a string

10.

Which one of the following is not a possible state for a pointer.

A.  

hold the address of the specific object

B.  

point one past the end of an object

C.  

zero

D.  

point to a type

PROGRAMMING IN C++ TOPICS