Knowee
Questions
Features
Study Tools

#include<stdio.h>#include<string.h>struct player { char pname[20];}pl;char* play(struct player *temp_pl){ strcpy(temp_pl->pname, "kohli"); return temp_pl->pname;}int main(){ strcpy(pl.pname, "dhoni"); printf("%s %s", pl.pname, play(&pl)); return 0;}

Question

#include<stdio.h>#include<string.h>struct player { char pname[20];}pl;char* play(struct player *temp_pl){ strcpy(temp_pl->pname, "kohli"); return temp_pl->pname;}int main(){ strcpy(pl.pname, "dhoni"); printf("%s %s", pl.pname, play(&pl)); return 0;}

🧐 Not the exact question you are looking for?Go ask a question

Solution

This is a C program that uses a structure to store player names and a function to change the player name. Here's a step-by-step explanation:

  1. The program starts with the inclusion of two header files: stdio.h for standard input/output functions and string.h for string manipulation functions.

  2. A structure named player is defined with a single member pname which is an array of characters (a string).

  3. An instance of the player structure named pl is declared globally.

  4. A function named play is defined which takes a pointer to a player structure as an argument. Inside this function, the pname of the passed structure is set to "kohli" using the strcpy function. The function then returns the pname of the passed structure.

  5. The main function is where the program execution starts. Inside main, the pname of the global pl structure is set to "dhoni" using strcpy.

  6. The printf function is then used to print the pname of pl and the result of the play function when passed a pointer to pl. Since the play function changes the pname of pl to "kohli", the output of the program will be "kohli kohli".

  7. The main function returns 0 to indicate successful execution of the program.

This problem has been solved

Similar Questions

0/0

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.