+ 2

Int A={1,2,3} int n=sizeof(A) /sizeof( A[0] ) ;

I want explanation for above code Please explain it.

6th Mar 2019, 6:15 PM
David Boga
David Boga - avatar
2 Answers
+ 1
Here, you have an array of integers (A). The size of of the array is equal to the size of an integer times the length of the array. So, sizeof(A) = sizeof(int) * 3 = 4 * 3 = 12 The size of the first element of the array (A[0]) is equal to the size of an integer. So sizeof(A[0]) = sizeof(int) = 4 sizeof(A) / sizeof(A[0]) = 12 / 4 = 3 //All assuming the size of an integer is 4 bytes
6th Mar 2019, 9:05 PM
Théophile
Théophile - avatar
+ 1
Since int has 4bits. Thus I have an integer array which has 3 elements of integer type, thus:- 3(number of elements in array)*4 (size of one int variable)= 12 Now, A [0] has size equivalent to 4 bits, Thus 12/4 (size of A [0])= 3 I hope u got it
12th Mar 2019, 4:26 AM
Mayank Mewar
Mayank Mewar - avatar