Showing posts with label Functions. Show all posts
Showing posts with label Functions. Show all posts

Saturday, 30 July 2016

Passing Address of Structure Variable to Function

Passing Address of Structure Variable to Function


#include<stdio.h>

void display(struct student *p);

struct student
{
            char name[20];
            int rollno;
            float mark;
};

int main()
{
            struct student S1;
            printf("\nEnter name rollno and mark of a student:");
            scanf("%s %d %f", S1.name, &S1.rollno, &S1.mark );
            display(&S1);
}

void display(struct student *p)
{
    printf("\n Name is %s \n Rollno is %d \n Mark is %f", p->name, p->rollno, p->mark );
}

Output:
Enter name rollno and mark of a student: aaa 11 80
 Name is aaa
 Rollno is 11
 Mark is 80.000000

Passing Structure Variable to Function

Passing Structure Variable to Function


#include<stdio.h>
void display(struct student);
struct student
{
            char name[20];           int rollno;        float mark;
};

void main()
{
            struct student S1;
            printf("\nEnter name rollno and mark of a student:");
            scanf("%s %d %f", S1.name, &S1.rollno, &S1.mark );
            display(S1);
}

void display(struct student stu)
{
            printf("\n Name is %s \n Rollno is %d \n Mark is %f", stu.name, stu.rollno, stu.mark );
}

Output:

Enter name rollno and mark of a student: aaa 11 80
 Name is aaa
 Rollno is 11
 Mark is 80.000000

Passing Individual Structure Members to Function

Passing Individual Structure Members to Function


#include<stdio.h>
void display(char nam[], int roll, float mrk);

struct student
{
            char name[20];
            int rollno;
            float mark;
};
main()
{
            struct student S1;
            printf("\nEnter name rollno and mark of a student:");
            scanf("%s %d %f", S1.name, &S1.rollno, &S1.mark );
            display(S1.name, S1.rollno, S1.mark );
}
void display(char nam[], int roll, float mrk)
{
            printf("\n Name is %s \n Rollno is %d \n Mark is %f", nam, roll, mrk );
}

Output:
Enter name rollno and mark of a student:     aaa          11        80
 Name is aaa
 Rollno is 11
 Mark is 80.000000


Goto Main Content:
https://tejaswinihbhat.blogspot.in/2016/07/data-structures-15CS33-Module1.html
https://tejaswinihbhat.blogspot.in/2016/07/structures.html