9.19.2011

malloc c program

/*Example of malloc function c program */

#include<stdio.h>
#include<conio.h>
struct st
{
  char nam[30];
  int clas;
  int marks;
};
int main()
{
 struct st *p;
 p=(struct st *)malloc(sizeof(struct st));
 printf("Enter your name : ");
 gets(p->nam);
 printf("Enter your class : ");
 scanf("%d",&p->clas);
 printf("Enter your obtained marks : ");
 scanf("%d",&p->marks);
 printf("\nYour name : %s",p->nam);
 printf("\nYour class : %d",p->clas);
 printf("\nYour obtained marks : %d",p->marks);
 getch();
 return 0;
}

      Output of above program :

Enter your name : Sid
Enter your class : 12
Enter your obtained marks : 483

Your name : Sid
Your class : 12
Your obtained marks : 483

No comments:

Post a Comment