How can I find the number of elements in an array?

If you have your array in scope you can use sizeof to determine its size in bytes and use the division to calculate the number of elements: #define NUM_OF_ELEMS 10 int arr[NUM_OF_ELEMS]; size_t NumberOfElements = sizeof(arr)/sizeof(arr[0]); If you receive an array as a function argument or allocate an array in heap you can not determine … Read more

what is the size of an enum type data in C++?

This is a C++ interview test question not homework. Then your interviewer needs to refresh his recollection with how the C++ standard works. And I quote: For an enumeration whose underlying type is not fixed, the underlying type is an integral type that can represent all the enumerator values defined in the enumeration. The whole … Read more

How can this structure have sizeof == 0?

Before C was standardized, many compilers would have had no difficulty handling zero-size types as long as code never tried to subtract one pointer to a zero-size type from another. Such types were useful, and supporting them was easier and cheaper than forbidding them. Other compilers decided to forbid such types, however, and some static-assertion … Read more

What is the size of void?

The type void has no size; that would be a compilation error. For the same reason you can’t do something like: void n; EDIT. To my surprise, doing sizeof(void) actually does compile in GNU C: $ echo ‘int main() { printf(“%d”, sizeof(void)); }’ | gcc -xc -w – && ./a.out 1 However, in C++ it … Read more

How can I print the result of sizeof() at compile time in C?

I was mucking around looking for similar functionality when I stumbled on this: Is it possible to print out the size of a C++ class at compile-time? Which gave me the idea for this: char (*__kaboom)[sizeof( YourTypeHere )] = 1; Which results in the following warning in VS2015: warning C4047: ‘initializing’: ‘DWORD (*)[88]’ differs in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)