Q.1.

Can I increase the size of dynamically allocated array?

Q.2.

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

Q.3.

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

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}
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
}
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}
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.

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}
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}
Q.10.

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

Q.11.

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

Q.12.

Can I increase the size of statically allocated array?

Q.13.

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

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}
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);
}
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
}
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}
Q.18.

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

Q.19.

Specify the 2 library functions to dynamically allocate memory?

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}