int a[10]; for(int i=0;i<5;i++) { a[i]=i; } int len=sizeof(a)/sizeof(int); print("%d",len);
When you code one line you need to understand why did you do like that Here small Explanation about each line.
int a[10];
This is an array declaration with the size of 10 and all elements are integer. This line will allocate 10 blocks of int size memory for your array with some random values(garbage values). For example its look like below.
|20|30|34|34|223|23|234|89|87|76|
for(int i=0; i<5; i++){ a[i] =i; }
This is a for loop which is run 5 times from i =0 to i =4 where ith element of an array will be replaced by i value.
When i = 0 array first element will be replaced by 0 with this line
a[i] =i;
a[0] =0 when i = 0
if a[0] is replaced by i then the array looks like below.
|0|30|34|34|223|23|234|89|87|76|
it continues until i <5 for each iteration, array will modify like below.
|0|1|34|34|223|23|234|89|87|76|
|0|1|2|34|223|23|234|89|87|76|
|0|1|2|3|223|23|234|89|87|76|
|0|1|2|3|4|23|234|89|87|76|
Clearly You can see that array size is didn't change. It remains 10