Question

C++ Help: Given the following code int num[30] = {2, 4, 6, 9, 5, -1, 7,...

C++ Help: Given the following code int num[30] = {2, 4, 6, 9, 5, -1, 7, 10}; Show the value of: a. num[3] + num[4] b. num[6] c. num[9] + 1 d. num[30]

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

In c++

array index starts from 0

so num[0] will give the first element of array named num so num[0] = 2 that is first element of array .

similarly num[1] will give the second element of the array named num . so num[1] = 4

now

(A) num[3] + num[4] will add index numbered 3 and 4 element of array num .

now num[3] = 9 and num[4] = 5

so num[3] + num[4] will gve 9+5 = 14

now for part B

num[6] will give the element at the 6th index in array num which is equal 7

now for part c  

since array size given is 30 and only 8 elements has been initialized . By default the remaining 22 elements ( 30 - 8) will

be implicitly initialized with value 0 .

we have num[9] + 1 . Now num[9] value will be by default 0 so adding( 0 + 1 ) result will be 1 .

now D

array size given is 30 elements int num[30]. so the valid index will be from 0 to 29 . so accessing array index 30 will display any garbage value which might be present in location of num(30).

Add a comment
Know the answer?
Add Answer to:
C++ Help: Given the following code int num[30] = {2, 4, 6, 9, 5, -1, 7,...
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