#include<stdio.h> struct employee{ char *empname; int salary;};int main(){ struct employee e, e1; e.empname = "Sridhar"; e1 = e; printf("%s %s", e.empname, e1.empname); return 0;}
Question
#include<stdio.h> struct employee{ char *empname; int salary;};int main(){ struct employee e, e1; e.empname = "Sridhar"; e1 = e; printf("%s %s", e.empname, e1.empname); return 0;}
Solution
The code you've written is in C language. It defines a structure employee with two members: a character pointer empname and an integer salary.
In the main function, two variables e and e1 of type employee are declared. The empname of e is assigned the string "Sridhar". Then, e1 is assigned the value of e, which means all members of e are copied to e1.
Finally, the printf function is used to print the empname of both e and e1. Since e1 was assigned the value of e, both printf calls will output "Sridhar".
Here's the step-by-step breakdown:
- Define a structure
employeewith a character pointerempnameand an integersalary. - Declare two variables
eande1of typeemployee. - Assign the string "Sridhar" to
empnameofe. - Assign
etoe1, copying all members ofetoe1. - Print the
empnameofeande1usingprintf. - Since
e1was assigned the value ofe, bothprintfcalls will output "Sridhar".
The output of the program will be: Sridhar Sridhar.
Similar Questions
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.