P202. WAP to design a function which allocates dynamic memory for 1 student database and returns starting address of that memory but return type of function is void.

 

#include<stdio.h>

#include<stdlib.h>

struct st

{

        int i;

        char ch;

        float f;

};

void data(struct st **);

void main()

{

 

        struct st *q;

        data(&q);

 

        printf("Enter integer value : ");

        scanf("%d",&q->i);

        printf("Enter character value : ");

        scanf(" %c",&q->ch);

        printf("Enter float value : ");

        scanf("%f",&q->f);

 

        printf("%d %c %f \n",q->i,q->ch,q->f);

 

}

 

void data(struct st **p)

{

        *p=malloc(sizeof(struct st));

 

}

Comments