integer array length and member addition – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-ICSE2016-01E #JAVA#4218    siteicon   siteicon  

Problem Statement - integer array length and member addition

If int x[] = { 4, 3, 7, 8, 9, 10 }; what are the values of p and q?
(i) p = x.length
(ii) q = x[2] + x[5] * x[1]

Solution

TC++ #4218

for array  int x[] = { 4, 3, 7, 8, 9, 10 };
(i) p = x.length
p would be 6 as array contains 6 members.

(ii) q = x[2] + x[5] * x[1]

q would be 37 as x[2]=7, x[5]=10,x[1]=3 so 7+10*3 would be 37.

Notes

  • Array index counting has to begin from 0.


Share

sunmitra| Created: 30-Mar-2018 | Updated: 16-Apr-2019|ICSE2016









Back