Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello can you help solve this problem num 5, 6 , 7 ? Thank you 4. What is the ou

ID: 3605051 • Letter: H

Question

Hello
can you help solve this problem num 5, 6 , 7 ?


Thank you

4. What is the output of the following code? int x = 50, y = 60, z = 70; int *ptr; ptr = &x; *ptr *= 10; ptr = &y; "ptr *= 5; ptr = &z; *ptr *= 2; 5. Assume pint is a pointer variable. Is each of the following statements vaid or invalid? If any is invalid, why? a. pint++ b. -pinti c. pint /= 2; d. pint *= 4; e, pint += x; // Assume x is an int. 6. Is each of the following definitions valid or invalid? If any is invalid, why? a. int ivar; int *ptr = &ivar; b. int ivar, *1ptr = &ivar; c. float fvar int *ptr = &fvar; d, int nums [50], *iptr= nums ; e, int *iptr = &ivar; int ivar; 7. The following function uses reference variables as parameters. Rewrite the function definition so it uses pointers instead of reference variables as input parameters. There is no change in the return type. int doSomething (int &x;, int y int temp = x; x=y*10; y temp * 10; return x t y

Explanation / Answer

(5)

++pint; //Valid
--pint; //Valid
// pint = pint/2; //InValid
// pint = pint*2; //InValid
pint = pint + x  //Valid


Explanation: division and multiplication is not valid on pointers


(6)

I)
int ival;
int *iptr = &ival; =====> Valid

II)
int ival, *iptr = &ival;====> Valid

III)
float fvar;
int *iptr = &fvar;===> InValid , because it Cannot convert 'float*' to 'int*' in initialization

IV)
int nums[50] , *IVAR = nums;===> Valid

V)
int *iptr = &ival; =====> InValid , ival was not declared in scope, It was declared later so compile will report and error
int ival;

(7) int doSomething( int *x, int *y ) {

int temp = *x;
*x = (*y) *10;
*y = temp * 10;
return *x + *y;

}


Thanks, let me know if there ois any concern.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote