Dumb array question
Can I use sizeof() on an array (not a pointer!)
Ex.
char myArray[1024];
int x = sizeof(myArray);
Does x = 1024? All I need is a yes or no, it was just a thought that came up.
==================
My (soon-to-be) Cherished Cookie of Appreciation:
-- MattB - for WinSock advice --
If the type is "int" your sizeof() will be 4096 (on any platform where your code is likely to run; even Merced et al if you use an lp64 compiler).
To get the number of elements in an array, do: sizeof(array)/sizeof(array[0])
To get the number of elements in an array, do: sizeof(array)/sizeof(array[0])
However, never use sizeof on a dynamically allocated array. sizeof is determined at compile time, so this:
char* letters
letters = (char*)malloc(64);
printf("%d", sizeof(letters));
would output 1.
char* letters
letters = (char*)malloc(64);
printf("%d", sizeof(letters));
would output 1.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement