Array Count
-
hello guys... I have this array which has 5 elements in it like this.
int arr[] = {1,2,3,4,5};
Now how do I find the length of this array? thnx
-
hello guys... I have this array which has 5 elements in it like this.
int arr[] = {1,2,3,4,5};
Now how do I find the length of this array? thnx
Not completely sure what you mean, but try this:
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
and use it like:int my_array_len = ARRAY_LENGTH(arr);
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > //TODO: Implement signature here<
-
hello guys... I have this array which has 5 elements in it like this.
int arr[] = {1,2,3,4,5};
Now how do I find the length of this array? thnx
Use the built-in macro: http://msdn.microsoft.com/en-us/library/ms175773%28v=vs.80%29.aspx[^]
Best wishes, Hans
-
hello guys... I have this array which has 5 elements in it like this.
int arr[] = {1,2,3,4,5};
Now how do I find the length of this array? thnx
overloaded Name wrote:
Now how do I find the length of this array? thnx
The size of the array, or the number of elements?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
-
hello guys... I have this array which has 5 elements in it like this.
int arr[] = {1,2,3,4,5};
Now how do I find the length of this array? thnx
Use
sizeof(arr) / 4;
#include <stdio.h>
void main()
{int arr\[\] = {1,2,3,4,5};
int x = sizeof(arr)/4;
printf("sizeof(arr) = %d \n", x );}
-
hello guys... I have this array which has 5 elements in it like this.
int arr[] = {1,2,3,4,5};
Now how do I find the length of this array? thnx
int main() { int a[] = {1,2,3,4,5}; printf("%d",sizeof(a)/sizeof(int)); getch(); }