Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



What is the output?

#include <stdio.h>
#include <stdlib.h>
void main(){
  int *ptr;
  ptr = (int*) calloc(3, sizeof(int));
  ptr[2] = 30;
  printf("%d", *ptr);
  free(ptr);
}





Solution

Explanation: The function calloc initializes all allocated memory blocks with zero. So ptr[0] is initialized to 0. The statement *ptr is equivalent to ptr[0]. $$ \text{Output: } 0 $$


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...