Linked Questions
176 questions linked to/from How do I determine the size of my array in C?
1813 votes
6 answers
205k views
What is ':-!!' in C?
I bumped into this strange macro code in /usr/include/linux/kernel.h: /* Force a compilation error if condition is true, but also produce a result (of value 0 and type size_t), so the expression ...
81 votes
12 answers
22k views
Array-size macro that rejects pointers
The standard array-size macro that is often taught is #define ARRAYSIZE(arr) (sizeof(arr) / sizeof(arr[0])) or some equivalent formation. However, this kind of thing silently succeeds when a pointer ...
51 votes
9 answers
99k views
Find the number of strings in an array of strings in C
char* names[]={"A", "B", "C"}; Is there a way to find the number of strings in the array? For example, in this case it should output: 3.
28 votes
4 answers
125k views
How to find the size of integer array
How to find the size of an integer array in C. Any method available without traversing the whole array once, to find out the size of the array.
19 votes
5 answers
59k views
Incompatible with parameter of type "LPCWSTR"
#include "stdafx.h" #include <windows.h> #include <stdio.h> #include <iostream> #include <dos.h> using namespace std; class Dir { public: char* cat; Dir() { ...
31 votes
3 answers
107k views
C sizeof char* array
I have a char* array as follows: char *tbl[] = { "1", "2", "3" }; How do I use the sizeof operator to get the number of elements of the array, here 3? The below did work, but is it correct? int n =...
9 votes
4 answers
14k views
How to get the length of a dynamically created array of structs in C?
I am currently trying to get the length of a dynamically generated array. It is an array of structs: typedef struct _my_data_ { unsigned int id; double latitude; double longitude; unsigned ...
19 votes
2 answers
931 views
Overhead data when writing to a binary file
I want to write a array containing 16bit integers as raw binary to a file and have tried with the following example: # define __int8_t_defined __intN_t (8, __QI__); __intN_t (16, __HI__); __intN_t (...
11 votes
5 answers
6k views
How does *(&arr + 1) - arr give the length in elements of array arr?
#include <iostream> using namespace std; int main() { int arr[5] = {5, 8, 1, 3, 6}; int len = *(&arr + 1) - arr; cout << "The length of the array is: " << len; ...
4 votes
5 answers
17k views
How to find the size of dynamic array [duplicate]
Is there any way I could find how much bytes are allocated for RandomArray in this code #include<stdio.h> #include<stdlib.h> int main() { int *RandomArray; int n; ...
3 votes
5 answers
3k views
Passing arrays as parameters in C
I (think I) understand that you can only retrieve the size of an array (using sizeof) if it is declared at compile time on the stack, e.g. int my_array[] = {1,2,3}; sizeof(my_array) == 3; As soon as ...
0 votes
4 answers
813 views
how can i know the number of elements in array [duplicate]
i run the following code but it kept printing "4" why its printing "4" and not "12"? and can I use malloc and then sizeof?(if i can then how) #include<stdio.h> int main() { int arr1[3]={1,...
3 votes
4 answers
339 views
Which way is better for array access?
I have a function, where I use a array of constants: void function(int Id){ int array1[4] = {4 constants}; int array2[4] = {4 constants}; for(int i=0; i<4; i++){ //accessing the array 1&...
4 votes
3 answers
8k views
Iterating through array of object pointers in C++ the old way (without range-based for)?
I'm not really versed in C++, but I came to the following code: BaseManager* allManagers[] = { mColorManager, mToolManager, mLayerManager, mPlaybackManager, mViewManager }; for ( ...
1 vote
3 answers
13k views
Error -1073741674 keeps happening which im not sure why
I am trying to input the rooms, sort them by price and create a text file afterward but there is always an error which I suspect has to do with the sizeof function In some compilers, it will compile ...