Professional Documents
Culture Documents
Multiple Choice Questions Based On Pointers and Dynamic Memory Allocation
Multiple Choice Questions Based On Pointers and Dynamic Memory Allocation
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 *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
pointer variable(s)?
a) Division
b) Multiplication
c) Casting
d) None of these
ans : C
7. Pick the correct answers.
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
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.
ans : C
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
15.
a)
int* malloc(int);
b)
char* malloc(char);
c)
d)
void* malloc(size_t);
ans: D