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

What is the error in the following code snippet? void func(int a) { a += 5; retu

ID: 3696891 • Letter: W

Question

What is the error in the following code snippet?

void func(int a) {

a += 5;

return a;

}

int main()

{

func(3);

return 0;

}

a. Cannot change the value of variable a

b. The function cannot be called with a direct value such as 3

c. The function cannot return a value

d. Variable a must be declared in the function

18. What is the output of:

int *x;

int a = 5;

x = &a;

cout<<*x<<" "<<a;

a. 5 0x444F

b. 5 5

c. 0x444F 5

d. 0x444F 0x444F

the answer is cb

please explain the answer. thanks so so much

Explanation / Answer

Answer1 ) c. The function cannot return a value

because the retirn type of function is void . if it would have been int or char etc the calling function expects a value of that type from the function but in case of void the calling function does not expect any value to be returned to it when the function is called.

2) b. 5 5

int *x;   //declaring a pointer variable to pint an int

int a = 5;   //declaring a variable of type int initialised to 5

x = &a; //pointer x stores the address of variale a

cout<<*x<<" "<<a;   //*x is the value stored at the address pointed by x

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