QUIZ ON : C LANGUAGE - POINTERS

POINTERS

00:00:00

Which of the following functions is used to free the allocated memory?

Option A. remove(var-name);
Option B. free(var-name);
Option C. delete(var-name);
Option D. dalloc(var-name);
True Answer B

Explanation :
The function free() is used to de-allocate the memory allocated by the functions malloc ( ), calloc ( ), etc, and return it to heap so that it can be used for other purposes. The argument of the function free ( ) is the pointer to the memory which is to be freed.

Which of the following functions is used to free the allocated memory?

Question No# : 01 out of 20

*ptr++ is equivalent to

Option A. ptr++
Option B. *ptr
Option C. ++ptr
Option D. ++*ptr
True Answer D

Explanation :

*ptr++ is equivalent to

Question No# : 02 out of 20

The return type of malloc function is void.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer B

Explanation :

The return type of malloc function is void.

Question No# : 03 out of 20

With every use of a memory allocation function, what function should be used to release allocated memory which is no longer needed?

Option A. unalloc()
Option B. Dropmem()
Option C. Dealloc()
Option D. free()
True Answer D

Explanation :

With every use of a memory allocation function, what function should be used to release allocated memory which is no longer needed?

Question No# : 04 out of 20

How will you free the allocated memory?

Option A. remove(var-name);
Option B. free(var-name);
Option C. delete(var-name);
Option D. dalloc(var-name);
True Answer B

Explanation :

How will you free the allocated memory?

Question No# : 05 out of 20

What will be the output of the following code?

main() { int c,d, *p1=&c,*p2=&d, x;
c =10,d =4;
x = –3* – *p2 / *p1 + 5;
printf(“%d ”,x);
}

Option A. 6
Option B. Invalid syntax because / * is used for comments.
Option C. 8
Option D. IInvalid syntax because three binary operators can’t be together in an expression.
True Answer B

Explanation :

What will be the output of the following code?

main() { int c,d, *p1=&c,*p2=&d, x;
c =10,d =4;
x = –3* – *p2 / *p1 + 5;
printf(“%d ”,x);
}

Question No# : 06 out of 20



Which of the following expression is equivalent to ++*ptr?

Option A. (*ptr)++
Option B. ++*(ptr)
Option C. (ptr)*++
Option D. (ptr)++*
True Answer A

Explanation :

Which of the following expression is equivalent to ++*ptr?

Question No# : 07 out of 20

Size of the pointer variable depends on the data type that it points to.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer A

Explanation :

Size of the pointer variable depends on the data type that it points to.

Question No# : 08 out of 20

Are the expression *ptr++ and ++*ptr are same?

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer B

Explanation :

Are the expression *ptr++ and ++*ptr are same?

Question No# : 09 out of 20

void (*ptr)(int); ptr is ptr is pointer to int that converts its type to void.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer B

Explanation :

void (*ptr)(int); ptr is ptr is pointer to int that converts its type to void.

Question No# : 10 out of 20

Size of the pointer variable depends on the data type that it points to.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer A

Explanation :

Size of the pointer variable depends on the data type that it points to.

Question No# : 11 out of 20

Which of the following declaration is not supported by C?

Option A. String str;
Option B. char *str;
Option C. float str = 3e2;
Option D. Both String str; & float str = 3e2;
True Answer A

Explanation :
It is legal in Java, but not in C.

Which of the following declaration is not supported by C?

Question No# : 12 out of 20

Pointers are used in a program to allocate memory before the program execution.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer B

Explanation :

Pointers are used in a program to allocate memory before the program execution.

Question No# : 13 out of 20

Difference between calloc() and malloc() is:

Option A. calloc() takes a single argument while malloc() needs two arguments
Option B. malloc() takes a single argument while calloc() needs two arguments
Option C. malloc() initializes the allocated memory to ZERO
Option D. calloc() initializes the allocated memory to NULL
True Answer B

Explanation :
The malloc() takes a single argument, while calloc() takess two. Second, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.Both malloc and calloc are used in C language for dynamic memory allocation they obtain blocks of memory dynamically.

Difference between calloc() and malloc() is:

Question No# : 14 out of 20

What do the following declarations signify? void *cmp();

Option A. cmp is a pointer to an void type.
Option B. cmp is a void type pointer variable.
Option C. cmp is a function that return a void pointer.
Option D. cmp function returns nothing.
True Answer C

Explanation :

What do the following declarations signify? void *cmp();

Question No# : 15 out of 20

Which of the following is a wrong pointer declaration?

Option A. int *int(a);
Option B. int *x, *y;
Option C. float *aptr;
Option D. int *x; float *y;
True Answer A

Explanation :

Which of the following is a wrong pointer declaration?

Question No# : 16 out of 20

Which of the following statements will not dynamically allocate space to store 10 integers?

Option A. int a[10];
Option B. int *p = (int *) malloc(10 * sizeof(int));
Option C. int *p = (int *) calloc(10, sizeof(int));
Option D. none of the above
True Answer A

Explanation :

Which of the following statements will not dynamically allocate space to store 10 integers?

Question No# : 17 out of 20

The three declarations char **apple, char *apple[], and char apple[][] are same.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer A

Explanation :

The three declarations char **apple, char *apple[], and char apple[][] are same.

Question No# : 18 out of 20

Two pointer variables cannot be subtracted.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer A

Explanation :

Two pointer variables cannot be subtracted.

Question No# : 19 out of 20

Which of the following declaration is illegal?

Option A. char *str = “Best C programming classes by Sanfoundry”;
Option B. char str[] = “Best C programming classes by Sanfoundry”;
Option C. char str[20] = “Best C programming classes by Sanfoundry”;
Option D. char[] str = “Best C programming classes by Sanfoundry”;
True Answer D

Explanation :
char[] str is a declaration in Java, but not in C.

Which of the following declaration is illegal?

Question No# : 20 out of 20