Taking J as sizeof(a)/sizeof(int) - 1

What is sizeof(a)/sizeof(int) - 1?
Can we take j = n -1, instead?

hello @udatta

yeah if size is already given then u can use it.

What is sizeof(a)/sizeof(int) - 1? Can you explain this? Like how is it pointing the last index of the array.

sizeof(a) will give total memory occupied by array a.

size(int) will give memory that a single int will take.

size(a)/size(int) will give number of integer we have in our array (which is size of array)

and size(a)/size(int) -1 will be last index of the array

So, this can be used when user is not taking the size of an array as input.

What if we write sizeof(a) - 1? This will also point to the last index.

yeah , we can use this when we hardcode the array elements without mentioning the array length .
or when we dont know the array length
like this->
int ar[]={1,2,3,4}

no size(a) will give total memory occupied by this array.
array memory is not equal to its size.
array memory = lenght of array * size of(int)

Can size.a - 1 give the size?

no … . . .
already explained here->

Oh got it. I was getting confused with the size function used for finding the length of string.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

One doubt the size function or the length function we use for string is not applicable for arrays. Right?

right . …

Got it. Thank You so much.