Using function with Struct user defined type also pointer


typedef struct
    int roll;
    char name[20];
    double gp;
} sTudent;

void inputStudent(sTudent *sp)

    printf("enter roll: ");
    printf("enter name:");
    scanf(" %[^\n]",sp->name);
    printf("enter grade point: \n");

void printStudent(sTudent sp)
    printf("Roll: %4d, Name: %-20s %10.2lf\n",sp.roll,,;

int main()
    sTudent s;

    return 0;

why we used *sp in one place and sp in another place ?there s a reason behind this
*sp means address is passing where after the local input takeup it will go but if not use  dereferencing then it will not go outside. So to write we need with address.

and in sp it is read only. so to print sp is enough to show.


It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *