Memory Allocation

26

Which header file should be included in c program to use malloc(), calloc(), realloc() and free()?

A. stdio.h
B. stdlib.h
C. ctype.h
D. assert.h

27

The pointer type returned by calloc and malloc after successful memory allocation is void pointer (*void)

A. True
B. False

28

What is the output of following c program?


#include<stdio.h>
#include<stdlib.h> 
int main()
{
    
    char* p;
    char* get();
    p = get();
    printf("%s",p);
    return 0;
}
char* get()
{
    char str[20] = {'a','b'};
    return str; 
}

A. ab
B. Some Garbage Value
C. error: returning local variable address
D. none of above

29

malloc() returns a int pointer if memory is allocated for storing integer's and a double pointer if memory is allocated for storing double's.


A. True
B. False

30

What is the output of following c program?


#include<stdio.h>
#include<stdlib.h> 
int main()
{
    
    char* p;
    char* get();
    p = get();
    printf("%s",p);
    return 0;
}
char* get()
{
    char *str = malloc(20*sizeof(char));
    str = "AB";
    return str; 
}

A. AB
B. Some Garbage Value
C. error: returing local variable address
D. None of the above