i dont know when each row ends
its not a string
that i could say stop when you see \0
can i find the length of row 0 by
sizeof(arr[0])/sizeof(int)
??
i dont know when each row ends
its not a string
that i could say stop when you see \0
can i find the length of row 0 by
sizeof(arr[0])/sizeof(int)
??
>> can i find the length of row 0 by
Not if it's a dynamically allocated array. In that case, you'll just need to store the size somewhere.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
how to find the length of a column 0
this is for row
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> void main() { int arr[10][10]={0}; int t=sizeof(arr[0])/sizeof(int); printf("%d",t); }
That only works if your array is declared with a static size like:can i find the length of row 0 by
sizeof(arr[0])/sizeof(int)
It will not work if you have used pointers to dynamically allocate the size of the rows.Code:int a[5][5];
EDIT: I guess I should have refreshed the page before posting, Sebastiani beat me to it.
The column isAs stated above, this doesn't at all work for dynamic arrays, since the sizeof only works for variables that are known size at the time of compilation. Dynamic arrays are specifically used when you do NOT know the size at time of compilation.Code:sizeof(arr) / (t * sizeof(arr[0][0]);
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
ahh so how to do this with dinamic allocation
??
(suppose i am not given the size and i need to find it)
It also doesn't work if you're passing the array to a function.
Quzah.
Hope is the first step on the road to disappointment.
>> how to find the length of a column 0
Hint: if sizeof(arr[0]) gives you the size of a single row and sizeof(a) gives you the size of the entire data structure, then the column length would be the result of some arithmetic operation between the two.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
>> ahh so how to do this with dinamic allocation
Wasn't that already answered?
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
no it havent been
it just been said that my method doesnt work on dinamic array
You CAN NOT find the size of a dynamic allocation in any generic/portable/reliable way. Of course, you can have markers to mark the end, but that's not generic, because some particular value (such as zero, -1, -32768 or some other value) is then "invalid" for the normal array values.
So, no, you can't do that.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Here is how to do it for dynamic arrays:
See what I did there?Code:int** a; a = malloc(COLUMN_SIZE * sizeof(int*)); for(i = 0; i < COLUMN_SIZE; i++) a[i] = malloc(ROW_SIZE * sizeof(int)); printf("column size is: %d\n", COLUMN_SIZE); printf("row size is: %d\n", ROW_SIZE);
i need to find some number in a cell of dinamic 2d array
how to do that
if i dont know where ends each row
and how many row are there
?
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }