asked 16.2k views
5 votes
Write a program that defines a type for a structure that stores information on a student in ENG EK 125. Declare two variables to be this structure type, and call a function to initialize both of the structure variables, using call-by-reference.

asked
User Jemz
by
8.2k points

1 Answer

2 votes

Answer:

Following are the program in the C Programming Language.

#include<stdio.h> //header file

#include<string.h> //header file

struct student//creating structure

{

//set integer variables

int marks;

int roll;

};

//define function

void initial(struct student *stu)

{

//set integer type variables

int marks=420;

int roll_no=45,i;

stu->marks=marks;//assigning the values

stu->roll=roll_no;//assigning the values

}

//define main method to call the function

int main()

{

struct student stu;

initial(&stu);//calling the function

printf("Total marks : %d\\",stu.marks); //print output

printf("Roll No. : %d\\",stu.roll); //print output

return 0;

}

Output:

Total marks : 420

Roll No. : 45

Step-by-step explanation:

Here, we define the structure "student" with a struct keyword for creating a structure.

  • inside the structure, we set two integer type variable "marks", "roll".

Then, we define a function "initial()" and pass an argument in the parameter of the function.

  • inside the function, we set two integer type variable "marks", "roll_no" and assign the value in the variable "marks" to 420 and variable "roll_no" to 45.
  • Assign the value in the structure's integer variables from the function's variable.

Finally, we set the main method inside it we call the function "initial()" and pass the value and then, we print the output with message.

answered
User Marc Hoogvliet
by
7.3k points