#include<stdio.h>
#include<stdlib.h> /* For malloc() and free()*/
#include<string.h> /* For strcpy() */
struct test{
char name[10];
unsigned int rollno;
unsigned int marks;
};
int main()
{
struct test *ptr;
ptr = (struct test *)malloc(1*sizeof(struct test));
/* ptr->name = "Sreekanth"; Not allowed */
strcpy(ptr->name, "Sreekanth"); /* We should copy char by char or use strcpy() */
/* printf("Enter the name:"); scanf("%s",ptr->name); */
/* printf("Enter the Roll no:"); scanf("%d",&ptr->rollno);*/
ptr->rollno = 101;
ptr->marks = 555;
printf("Name: %s\n Roll no: %d\n Marks: %d\n",ptr->name, ptr->rollno, ptr->marks);
free(ptr);
return 0;
}
#include<stdlib.h> /* For malloc() and free()*/
#include<string.h> /* For strcpy() */
struct test{
char name[10];
unsigned int rollno;
unsigned int marks;
};
int main()
{
struct test *ptr;
ptr = (struct test *)malloc(1*sizeof(struct test));
/* ptr->name = "Sreekanth"; Not allowed */
strcpy(ptr->name, "Sreekanth"); /* We should copy char by char or use strcpy() */
/* printf("Enter the name:"); scanf("%s",ptr->name); */
/* printf("Enter the Roll no:"); scanf("%d",&ptr->rollno);*/
ptr->rollno = 101;
ptr->marks = 555;
printf("Name: %s\n Roll no: %d\n Marks: %d\n",ptr->name, ptr->rollno, ptr->marks);
free(ptr);
return 0;
}
No comments:
Post a Comment