E
Excluded_Middle
consider the following code
/***********************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct student {
int id;
char name [100];
struct student * next;
};
void printStudents(struct student *p) {
printf("Printing the list of students \n");
for (p; p != NULL; p=p->next)
printf ("id=%d name=%s \n",p->id,p->name);
printf("\n");
}
int main () {
struct student *p, *head, *mid, *tail;
p=(struct student *) malloc (sizeof(struct student));
p->id=12; strcpy(p->name,"Tom"); p->next=NULL; head=p;
tail=p;
p=(struct student *) malloc (sizeof(struct student));
p->id=7; strcpy(p->name,"Bob"); p->next=NULL; tail->
next=p; tail=p; mid=p;
p=(struct student *) malloc (sizeof(struct student));
p->id=9; strcpy(p->name,"Rob"); p->next=NULL;
tail-> next=p; tail=p;
printStudents(head);
printStudents(head);
return 0;
}
/****************************************************************************/
My question is head is a pointer to student struct and is passed by
ref to function printStudents when I call this function for the second
time it give me same result why?
Is there any that I can change head in printStudent and that change
also effects in main function.
thank you.
/***********************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct student {
int id;
char name [100];
struct student * next;
};
void printStudents(struct student *p) {
printf("Printing the list of students \n");
for (p; p != NULL; p=p->next)
printf ("id=%d name=%s \n",p->id,p->name);
printf("\n");
}
int main () {
struct student *p, *head, *mid, *tail;
p=(struct student *) malloc (sizeof(struct student));
p->id=12; strcpy(p->name,"Tom"); p->next=NULL; head=p;
tail=p;
p=(struct student *) malloc (sizeof(struct student));
p->id=7; strcpy(p->name,"Bob"); p->next=NULL; tail->
next=p; tail=p; mid=p;
p=(struct student *) malloc (sizeof(struct student));
p->id=9; strcpy(p->name,"Rob"); p->next=NULL;
tail-> next=p; tail=p;
printStudents(head);
printStudents(head);
return 0;
}
/****************************************************************************/
My question is head is a pointer to student struct and is passed by
ref to function printStudents when I call this function for the second
time it give me same result why?
Is there any that I can change head in printStudent and that change
also effects in main function.
thank you.