Linked Questions
176 questions linked to/from How do I determine the size of my array in C?
2 votes
4 answers
1k views
Sizeof(Array) Prints wrong value [duplicate]
I have initialized an array of size 10 but on printing the sizof array shows 40 . The code is as follows , #include <iostream> using namespace std; int main() { int arr[10] = {2,4,5,...
4 votes
4 answers
2k views
How to get the number of elements of a C-array like this? [duplicate]
I have a C-array like this: double arr[] = { 0.0, 0.1, 0.2, 0.5, 0.1, 0.2, 0.3, 0.4, 0.2, 0.0, 0.1, 0.3 }; Is it safe to get the number of elements like this? int numElements = ...
-2 votes
2 answers
7k views
How do I get the length of an array in C? [duplicate]
How can I get the length of an array in C, I tried it how i get it in other languages but it doesn't work like this: int array [5]; for(int i = 0; i < array.length; i++) {..
-1 votes
1 answer
17k views
Find size of double * array C++ [duplicate]
If I have declared a double *positions[2] array, is there a way of finding the actual size of the double *positions[2] array? Is there like a sizeof function to find the size? I have tried an ...
3 votes
2 answers
4k views
Abort trap: 6 error when working with array in C [duplicate]
I am a beginner to C and am trying to get more familiar with arrays and the concept of manual memory allocation by doing simple exercises. I have been reading all the (many) questions on SO regarding ...
0 votes
3 answers
2k views
chararray size and length are not the same [duplicate]
I just started learning C after I already got a few years experience in Python, C# and Java. I learned in a tutorial, that char anything[] is always a pointer. (Today, someone told me this is wrong) - ...
0 votes
2 answers
2k views
Make a combination of two arrays to form a pair of each item [duplicate]
I have two arrays array1 of size 3 and array2 of size 2. I wish to form a pair of each item from both arrays. That is; int array1[] = {1, 2, 3}; int array2[] = {9, 4}; Results I'm hoping to achieve: ...
-1 votes
5 answers
2k views
Using strlen() with Array Integers or Float [duplicate]
Is there a way, I can use of strlen() to find the length of the arrays, instead of specifying in the loop. First Code: Working With x < 4 Which is the size of the array of temps[4]. #include <...
1 vote
2 answers
2k views
length of an array of function pointers [duplicate]
Is there a safe way to get the length of an array of function pointers? Would the following work? sizeof((uintptr_t)(*fp) / sizeof(uintptr_t)(*fp[0]))
2 votes
3 answers
1k views
In C, why is the sizeof function used as the denominator to store the number of elements in an array? [duplicate]
More than once I have seen the sizeof operator used on index 0 of an array act as the denominator when storing the number of elements of an array. My question is why use the sizeof operator instead of ...
1 vote
2 answers
3k views
C converting 8 bit values into 16 bit values [duplicate]
I have a situation where I pass an array containing 2 1 byte values to a function, but somehow the function thinks the array is 4 bytes long, which messes up my bit manipulation big-time. I even tried ...
1 vote
2 answers
2k views
Creating a list and struct arrays using C [duplicate]
I'm currently starting out with C so I thought I'd try creating my own custom list. Here's the code: #include <stdio.h> struct list { char data[10]; struct list *n; }; void clist(...
1 vote
4 answers
212 views
For loop assignments overflow into another variable [duplicate]
I am trying to use a for loop to assign values to an array in C (I'm using minGW). At first I tried doing: double flag[5] = {0.1}; but that only assigned the first variable in the array to 0.1. ...
-2 votes
1 answer
2k views
finding the size of an unknown array in C [duplicate]
We have been given a large array of unknown size with elements given , is there any function or something other through which we can find the size of that array in language C int a[]={4,6,4,26,3,2,5,...
0 votes
2 answers
347 views
How can we iterate through an array of integers when we do not know the size of the array? [duplicate]
This is a code from geeksforgeeks counting sort implementation: The have used the below for loop to iterate through a string - char arr[] = "geeksforgeeks"; for(i = 0; arr[i]; ++i) ++count[arr[...