Given the following: struct cell { int num; float num2; } ; struct person { int
ID: 3536224 • Letter: G
Question
Given the following: struct cell { int num; float num2; } ; struct person { int age; float income; } ; person p1,p2,p3; cell s,t; s.num = 0; s.num2 = 2.5; //initialize s p2.age = 25; p2.income = 9999.99; //initialize p2 t = s; //assignment one p1 = p2; //assignment two p1 = s; //assignment three p2 = p3; //assignment four p3.age = s.num; //assignment five p3.income = s.num2; //assignment six (12pts) For each assignment above, answer the following: (a) will it give a problem? (b) why or why not? (c) ifthere is a problem, when does the problem occur? Is there an error message?Explanation / Answer
1. yes it will give compilation error
2. reason:- a. because in assignment three p1 = s; we are assignning a variable of type cell to a variable of type person. The compilation error will be 'initializing' : cannot convert from 'cell' to 'person'
b. in assignment 4 p2=p3 , we have used the variable p3 without being initialized it with some legal values, so it will create errors like "The variable 'p3' is being used without being initialized.
3. so problem occur during compilation of the posted program
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.