Linked Questions
176 questions linked to/from How do I determine the size of my array in C?
1 vote
2 answers
22k views
How to check if element is included in array with arduino?
I have an array called numbers and I want to test if a certain number is included in that array. void loop(){ if (arrayIncludeElement(numbers, mynumber)){ // Do something } else { // Do ...
11 votes
2 answers
4k views
C++ function instrumentation via clang++'s -finstrument-functions : how to ignore internal std library calls?
Let's say I have a function like: template<typename It, typename Cmp> void mysort( It begin, It end, Cmp cmp ) { std::sort( begin, end, cmp ); } When I compile this using -finstrument-...
0 votes
4 answers
5k views
Counting number of elements in an array using while loop in C
#include <stdio.h> int main() { int x[] = {22, 8, 87, 76, 45, 43, 34, 13, 51, 15}; int count = 0; while (x[count] != '\0') { count++; } printf("%d", count); return 0; } I cannot ...
0 votes
4 answers
9k views
error: request for member 'size' in '', which is of non-class type 'int*'
I dont know why I have this problem right now! error: request for member 'size' in 'isbn', which is of non-class type 'int*' I am trying to get how many elements (integers) are in isbn. class Book{ ...
0 votes
6 answers
3k views
Declaring array of int in C++ under Xcode
What is the difference between these two declarations? int myints[5]; array<int,5> myints; If I use the first declarations and the function size(), there will be a error "Member reference base ...
6 votes
1 answer
1k views
Declaring an array with variable length in C
I know defining an array in C is not possible with variable length, but what about just declaring it? #include <stdio.h> int main () { int num = 5; int array[num]; printf("%d\n",...
2 votes
3 answers
2k views
Pass a constant two-dimensional array to function as a structure in C
I'm a novice in C and I need a structure to pass constant two-dimensional arrays to function as one parameter. I want to make this const int a_size_x = 20; const int a_size_y = 30; const int ...
1 vote
1 answer
3k views
Sizeof on an array warning [duplicate]
I can get the sizeof an object in an array in a local function: int xa[] = {3,5}; printf("Sizeof: %zu\n", sizeof(xa)); Sizeof: 8 But if I pass it to a function, I get a warning: void ...
2 votes
1 answer
3k views
initializing a 2D array (Matrix) in C++
I am trying to create a 2D array by a for loop but I get some garbage random numbers code: unsigned int i, j; int matrix[10][10];//={{},{}}; for (i = 0; i < sizeof(matrix[i])/sizeof(int); i++) { ...
1 vote
2 answers
2k views
Trying to get an array.length to work in for loop
Can someone help me figure out why this is not working. int main() { int A[100]; for(int i=0; i<A.length; i++) { } return 0; } Here is my error [Error] request for member '...
-1 votes
1 answer
3k views
C - Buffer overflow with strcpy() and strncpy()
I'm taking the CS50 course on edx and I'm supposed to write a code in C that encrypts a message using the Vigenere Cipher. And I did. But the problem is I keep getting buffer overflow. If I use a ...
3 votes
4 answers
717 views
How to dynamically calculate the size of a dynamically allocated memory
Considering the code as follows: int i, a_size, s_size, n; char **a; a_size = 100; // examples s_size = 10; a = malloc(a_size * sizeof(char*)); for (int i = 0; i < a_size; i++) a[i] = malloc(...
1 vote
2 answers
4k views
Issue finding the largest float in array
I'm having a problem in C when I'm trying to find the largest float of an array, but my largest int works just fine. I think I might be going past the array length but I don't see how it is possible. ...
3 votes
6 answers
484 views
Basic array usage in C?
Is this how you guys get size of an array in ANSI-C99? Seems kind of, um clunky coming from higher language. int tests[7]; for (int i=0; i<sizeof(tests)/sizeof(int); i++) { tests[i] = rand(); ...
1 vote
5 answers
1k views
Count elements of an unknown type array
Hello i am trying to write a function which return the number of elements of the array passed as parameter, the function have to work on an array of any type. I tried this: int nb_elems(void* array) {...