How can you find the number of elements stored in a static array at a time?

Showing Answers 1 - 18 of 18 Answers

Aruna.S,Narayanan

  • Nov 17th, 2006
 

The number of elements at given time can be found using the formula

int n=sizeof(arrayname)/sizeof(array data type);

int a[]={2,3,4,5,6};

int n = sizeof(a)/sizeof(int);

  Was this answer useful?  Yes

Sundar A

  • Nov 29th, 2006
 

even "size(a)/sizeof(a[0])" Should do fine

  Was this answer useful?  Yes

sweety

  • Dec 24th, 2006
 

actually your answer is for array which contain integer only .......give general form

  Was this answer useful?  Yes

fkhanoom

  • Mar 19th, 2008
 

Array elements are stored in contiguous memory and arrays can hold elements of one type only. Therefore,

nArrElmt = sizeof(arr)/sizeof(arr[0]);



  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions