Q.1

Can I increase the size of dynamically allocated array?

  • Yes
  • No
Q.2

What function should be used to free the memory allocated by calloc() ?

  • dealloc();
  • malloc(variable_name, 0)
  • free();
  • memalloc(variable_name, 0)
Q.3

Which header file should be included to use functions like malloc() and calloc()?

  • memory.h
  • stdlib.h
  • string.h
  • dos.h
Q.4

What will be the output of the program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int *p;
    p = (int *)malloc(20); /* Assume p has address of*/
    free(p);
    printf("%u", p);
    return}
  • 1314
  • Garbage value
  • 1316
  • Random address
Q.5

Point out the error in the following program.

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int *a[3];
    a = (int*) malloc(sizeof(int)*3);
    free(a);
    return
}
  • Error: unable to allocate memory
  • Error: We cannot store address of allocated memory in a
  • Error: unable to free memory
  • No error
Q.6

Point out the correct statement will let you access the elements of the array using 'p' in the following program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int i, j;
    int(*p)[3];
    p = (int(*)[3])malloc(3*sizeof(*p));
    return}
  • for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
            printf("%d", p[i+j]);
    }
    
  • for(i=0; i<3; i++)
        printf("%d", p[i]);
    
  • for(i=0; i<3; i++)
    {
        for(j=0; j<3; j++)
            printf("%d", p[i][j]);
    }
    
  • for(j=0; j<3; j++)
        printf("%d", p[i][j]);
    
Q.7

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

  • True
  • False
Q.8

What will be the output of the program (16-bit platform)?

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int *p;
    p = (int *)malloc(20);
    printf("%d\n", sizeof(p));
    free(p);
    return}
  • 4
  • 2
  • 8
  • Garbage value
Q.9

Point out the error in the following program.

#include<stdio.h>
#include<stdlib.h>

int main()
{
    char *ptr;
    *ptr = (char)malloc(30);
    strcpy(ptr, "RAM");
    printf("%s", ptr);
    free(ptr);
    return}
  • Error: in strcpy() statement.
  • Error: in *ptr = (char)malloc(30);
  • Error: in free(ptr);
  • No error
Q.10

Which of the following statement is correct prototype of the malloc() function in c ?

  • int* malloc(int);
  • char* malloc(char);
  • unsigned int* malloc(unsigned int);
  • void* malloc(size_t);
Q.11

malloc() allocates memory from the heap and not from the stack.

  • True
  • False
Q.12

Can I increase the size of statically allocated array?

  • Yes
  • No
Q.13

When we dynamically allocate memory is there any way to free memory during run time?

  • Yes
  • No
Q.14

How will you free the memory allocated by the following program?

#include<stdio.h>
#include<stdlib.h>
#define MAXROW 3
#define MAXCOL 4

int main()
{
    int **p, i, j;
    p = (int **) malloc(MAXROW * sizeof(int*));
    return}
  • memfree(int p);
  • dealloc(p);
  • malloc(p, 0);
  • free(p);
Q.15

What will be the output of the program?

#include<stdio.h>
#include<string.h>

int main()
{
    char *s;
    char *fun();
    s = fun();
    printf("%s\n", s);
    return}
char *fun()
{
    char buffer[30];
    strcpy(buffer, "RAM");
    return (buffer);
}
  • 0xffff
  • Garbage value
  • 0xffee
  • Error
Q.16

Point out the correct statement which correctly free the memory pointed to by 's' and 'p' in the following program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
    struct ex
    {
        int i;
        float j;
        char *s
    };
    struct ex *p;
    p = (struct ex *)malloc(sizeof(struct ex));
    p->s = (char*)malloc(20);
    return
}
  • free(p); , free(p->s);
  • free(p->s); , free(p);
  • free(p->s);
  • free(p);
Q.17

Point out the correct statement which correctly allocates memory dynamically forarray following program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int *p, i, j;
    /* Add statement here */
    for(i=i<i++)
    {
        for(j=j<j++)
        {
            p[i*4+j] = i;
            printf("%d", p[i*4+j]);
        }
    }
    return}
  • p = (int*) malloc(3, 4);
  • p = (int*) malloc(3*sizeof(int));
  • p = malloc(3*4*sizeof(int));
  • p = (int*) malloc(3*4*sizeof(int));
Q.18

malloc() returns a NULL if it fails to allocate the requested memory.

  • True
  • False
Q.19

Specify the 2 library functions to dynamically allocate memory?

  • malloc() and memalloc()
  • alloc() and memalloc()
  • malloc() and calloc()
  • memalloc() and faralloc()
Q.20

What will be the output of the program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
    union test
    {
        int i;
        float f;
        char c;
    };
    union test *t;
    t = (union test *)malloc(sizeof(union test));
    t->f = 10.10f;
    printf("%f", t->f);
    return}
  • 10
  • Garbage value
  • 10.100000
  • Error
0 h : 0 m : 1 s