# Which one of the following statements allocates enough space to hold an array of 10 integers that are initialized to 0 ?

A) int *ptr = (int *) calloc(10,sizeof(int));
b) int *ptr = (int *) alloc( 10*sizeof(int));
c) int *ptr = (int *) malloc( 10*sizeof(int));
d) int *ptr = (int *)calloc(10*sizeof(int));

Answered by Ragini rani on 2005-05-13 09:01:56: a is the correct ans Calloc allocates space and initialized them to 0
This question is related to BirlaSoft Interview

#### surya

• Mar 23rd, 2005

C is the correct answer. Malloc allocates enough space for 10 integers

#### Ragini rani

• May 13th, 2005

a is the correct ans Calloc allocates space and initialized them to 0

#### vipin dhaiya

• Jul 27th, 2005

ans a is correct because calloc function ll initialize the array to zero

#### gaurav dutta

• Jul 30th, 2005

#### sandeep paliwal

• Aug 23rd, 2005

(a) is the correct answer because calloc initialize the array to zero.....and since 2 arguments are needed for calling calloc function option (d) is incorrect

#### sameer_gupta Profile Answers by sameer_gupta

• May 2nd, 2006

a is the answer,as calloc syntax in d is wrong

#### yash grotra

• Jul 24th, 2006

a is the correct answer because calloc initilize the array to zero.

#### Santh kumar

• Oct 3rd, 2006

Hi all, i'd like clear difference b/w those  2 functions.

There are 2 differences.

First, is in the number of arguments. malloc() takes a single argument(memory required in bytes), while calloc() needs 2 arguments(number of variables to allocate memory, size in bytes of a single variable).

Secondly, malloc() doesnot initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.

The difference b/w malloc and calloc are: 1. malloc() allocates byte of memory where as calloc()allocates block of memory.

malloc(s); returns a pointer for enough storage for an object of s bytes. calloc(n,s); returns a pointer for enough contiguous storage for n objects,each of s bytes. The storage is all initialised to zeros.

#### Purvi mehta

• Nov 8th, 2006

Ans:- C