Question

Consider the following function definition and variable declarations: void square(int &n){n= n*n;} int arr[] = {1,...

Consider the following function definition and variable declarations:

void square(int &n){n= n*n;}

int arr[] = {1, 2, 3};

int number = 4;

Which of the following function calls are acceptable? (can have multiple answer)

a.square(1);

b.square(2);

c.square(arr[number]);

d.square(number);

What is the output of the following code segment?

int arr[] = {1, 4, 1, 0};

for (int i=0; i < 4; ++i)

    cout<<arr[i]*2;

a.1014

b.1 4 1 0 (space in between each number)

c.1410

d.0140

e.None of the above

Given array declaration int a[] = {1, 2, 3};, the value of a[3] is

a.1

b.2

c.3

d.Undefined (or out-of-bound error)

e.None of the above

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question 1:

Answer :

c.square(arr[number]);

d.square(number);

Explanation :

  • Here square(arr[number]); is acceptable but square(arr[4]) will be 0
  • square(number); will be 16 because square(4) will be 16

*********************************

Question 2:

Answer :e.None of the above

Explanation :

  • Here each element from the array will be multiplied by 2
  • hence the output will be 2820

************************************

Question 3:

Answer :e.None of the above

Explanation :Here a[3] will be 0 because array is defined with three elements and a[3] will be 0.

************************************

Add a comment
Know the answer?
Add Answer to:
Consider the following function definition and variable declarations: void square(int &n){n= n*n;} int arr[] = {1,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT