Swapping two values using malloc function in C | Swapping Numbers using malloc in C
#include#include struct stud { char nam[30]; struct stud *next; }; struct stud *p,*q; int main() { p=(struct stud *)malloc(sizeof(struct stud)); q=(struct stud *)malloc(sizeof(struct stud)); printf("Enter name p : "); gets(p->nam); //fflush(stdin); printf("Enter name q : "); gets(q->nam); p->next=q; q->next=p; printf("\nName of p : %s",p->next->nam); printf("\nName of q : %s",q->next->nam); getch(); return 0; }
Enter name p : Ram
Enter name q : Shyam
Name of p : Shyam
Name of q : Ram
No comments:
Post a Comment