Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

Multiple choice questions based on pointers and dynamic

memory allocation
1. Prior to using a pointer variable it should be

a) declared
b) initialized
c) both declared and initialized
d) none of these
ans : C
2. A pointer variable to an integer can be created by the

declaration
a) Int p*;
b) Int *p;
c) Int +p;
d) Int &p;
ans : B
3. A pointer variable can be

a) Passed to a function
b) Changed within a function
c) Returned by a function
d) Can be assigned an integer value
ans : C
4. What will be the output for following program
main()
{

int i[3] = {1,4,6} ;

int *j;
j=i;
++j;
j++;
printf(%d,*j);
getch();

a) 4
b) 6
c) 1
d) None of above

ans : 6
5. Whenever pointer is incremented it points to the

immediately next location of its -------------------a) Memory


b) Type
c) Value
d) None of above
ans : B
6. Which of the following operators can be applied to

pointer variable(s)?
a) Division
b) Multiplication
c) Casting
d) None of these

ans : C
7. Pick the correct answers.

If x is an one dimensional array, then


a. &x[i] is same as x + i 1
b. *(x+i) is same as *(&x[i])
c. *(x+i) is same as x[i]
d. Both (b) & (c)
ans :
8. The declaration

int (*p) [5];


means
a) P is a one dimensional array of size 5, of pointers to
integers
b) P is a pointer to a 5 element integer array
c) The same as int *p[5];
d) None of above
ans : B

9. Which of the following comments about arrays and

pointers is/are not true?


a) Both are exactly same
b) Array is a constant pointer
c) Pointer is an one- dimensional and dynamic array
d) All of these

ans :

10.
Pointer that stores the address of any type of variable is
known as.............
a) Wild pointer
b) Null pointer
c) Void pointer
d) Array of pointer

ans : C
11.
Determine the output
#include<iostream.h>
#include<conio.h>
main()
{
int *ptr1;
int **ptr2;
int a;
a=100;
ptr1=&(++a);
ptr2=&ptr1;
printf(contents of ptr1=%d",*ptr1);
printf(contents of ptr2=%d",**ptr2;
getch();
}
a) 100 100
b) 100 101
c) 101 101
d) 100

ans : C

Which header file should be included to use


functions like malloc() and calloc()?

12.

a) Memory.h
b) Stdlib.h
c) Dos.h
d) Iostream.h

ans : B
Specify the 2 library functions to dynamically
allocate memory?

13.

a) Mallc and memalloc()


b) Calloc() and memalloc()
c) Malloc() and calloc()
d) Memalloc() and faralloc()

ans : C

What will be the output of the program (16-bit


platform)?

14.

#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p;
p = (int *)malloc(20);
printf("%d\n", sizeof(p));
free(p);

return 0;

a) 8
b) 4
c) 2
d) garbage value

ans : C

Which of the following statement is correct


prototype of the malloc() function in c ?

15.
a)

int* malloc(int);

b)

char* malloc(char);

c)

unsigned int* malloc(unsigned int);

d)

void* malloc(size_t);
ans: D

You might also like