Discussion
Which of the following statements are correct about 6 used in the program?
int num[6];
num[6]=21;
Answer: B
Correct answer: In the first statement 6 specifies a array size, whereas in the second statement it specifies a particular element of array.
In a declaration, int num[6];, the 6 is the size - how many elements to reserve. In an expression, num[6] = 21;, the 6 is a subscript naming one element. The same notation means different things in the two positions, and here the second use is in fact out of bounds: valid subscripts run 0 to 5.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development