I filled up my array with the following elements:  91.54 -96.58 -5.14 -78.25 15.33 89.34 -12.76 -92.56 38.21 36.11 -43.83 48.39 79.57 34.34 -26.07 -10.47 54.37 9.06 -67.17 53.83 -8.13 89.71 85.77 -68.44 -88.22 -86.24 -5.44 53.32 75.62 51.08 -80.42 91.94 33.5 -29.44 70.33 70.56 -66.75 10.41 92.84 -33.14 -0.34   The last element of my array is the sum of all of these float values.  And I want to print the number of elements with the sizeof technique.  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt;   int main(){      FILE *f = fopen("floats.txt", "r");     float *V, num, sum = 0;     int i = 0;     V = (float *)malloc(sizeof(float));      while(fscanf(f, "%f", &amp;num) == 1){         i++;         V = (float *)realloc(V, i*sizeof(float));         V[(i-1)] = num;         sum += num;     }      i++;     V = (float *)realloc(V, i*sizeof(float));     V[(i-1)] = sum;      /*printf("%f\n", soma);     printf("%f\n", V[(i-1)]);     printf("%f\n", size);*/      printf("%ld\n", sizeof(V)/sizeof(V[0]));     printf("Sum = %f\n", V[sizeof(V)/sizeof(V[0]) -1]);     return 0;  }     The number of elements must be 41 but it is printing 2 and the Sum must be 375.779999 the last element stored in the array.  Why is this printing 2 instead of 41? That is my main question!
680
First off, here is some code:  int main()  {     int days[] = {1,2,3,4,5};     int *ptr = days;     printf("%u\n", sizeof(days));     printf("%u\n", sizeof(ptr));      return 0; }   Is there a way to find out the size of the array that ptr is pointing to (instead of just giving its size, which is four bytes on a 32-bit system)?
32884
If I define an array in PHP such as (I don't define its size):  $cart = array();   Do I simply add elements to it using the following?  $cart[] = 13; $cart[] = "foo"; $cart[] = obj;   Don't arrays in PHP have an add method, for example, cart.add(13)?
123088
I am writing a SQL query creator using some parameters. In Java, it's very easy to detect the last element of an array from inside the for loop by just checking the current array position with the array length.  for(int i=0; i&lt; arr.length;i++){      boolean isLastElem = i== (arr.length -1) ? true : false;         }   In PHP they have non-integer indexes to access arrays. So you must iterate over an array using a foreach loop. This becomes problematic when you need to take some decision (in my case to append or/and parameter while building query).   I am sure there must be some standard way of doing this.   How do you solve this in PHP?
116007
In , is the following the only way to get the number of elements?  arr.__len__()   If so, why the strange syntax?
1748
I have a data like this:  input.txt  1 0000100101000000 1 0000010100000000 2 1110000001000000 2 1111000000001000 3 0000000111111111 3 1111111100000000 4 8888345500000000 4 0000000000000000   and I want to sum up the values within eachtwo rows with the same row number: output:  output.txt  1 0000110201000000 2 2221000001001000 3 1111111211111111 4 8888345500000000   any suggestion please? my real dat had 8000 rows with 45000 digit in each line
84331
What is the purpose of the strdup() function in C?
75403
I have an array:  data.Dealer.car[0] data.Dealer.car[1] data.Dealer.car[2]   If I do this:  alert(data.Dealer.car.length); delete data.Dealer.car[1]; alert(data.Dealer.car.length);   It gives me the same count each time. Does the removed element still exist?
17976
I'm using C++ to understand how exactly pointers work. I have this piece of code using arrays, which I'm using just to understand how the equivalent works with pointers.  int main() {         int arr[10] = {1,2,3};         char arr2[10] = {'c','i','a','o','\0'};     cout &lt;&lt; arr &lt;&lt; endl;     cout &lt;&lt; arr2 &lt;&lt; endl; }   However when I run this, arr outputs the address of the first element of the array of ints (as expected) but arr2 doesn't output the address of the first element of the array of chars; it actually prints "ciao".  What is it that I'm missing or that I haven't learned yet about this?
30227
I was under the impression that the maximum length of a single argument was not the problem here so much as the total size of the overall argument array plus the size of the environment, which is limited to ARG_MAX. Thus I thought that something like the following would succeed:  env_size=$(cat /proc/$$/environ | wc -c) (( arg_size = $(getconf ARG_MAX) - $env_size - 100 )) /bin/echo $(tr -dc [:alnum:] &lt;/dev/urandom | head -c $arg_size) &gt;/dev/null   With the - 100 being more than enough to account for the difference between the size of the environment in the shell and the echo process. Instead I got the error:  bash: /bin/echo: Argument list too long   After playing around for a while, I found that the maximum  was a full hex order of magnitude smaller:  /bin/echo \   $(tr -dc [:alnum:] &lt;/dev/urandom | head -c $(($(getconf ARG_MAX)/16-1))) \   &gt;/dev/null   When the minus one is removed, the error returns. Seemingly the maximum for a single argument is actually ARG_MAX/16 and the -1 accounts for the null byte placed at the end of the string in the argument array.  Another issue is that when the argument is repeated, the total size of the argument array can be closer to ARG_MAX, but still not quite there:  args=( $(tr -dc [:alnum:] &lt;/dev/urandom | head -c $(($(getconf ARG_MAX)/16-1))) ) for x in {1..14}; do   args+=( ${args[0]} ) done  /bin/echo "${args[@]}" "${args[0]:6534}" &gt;/dev/null   Using "${args[0]:6533}" here makes the last argument 1 byte longer and gives the Argument list too long error. This difference is unlikely to be accounted for by the size of the environment given:  $ cat /proc/$$/environ | wc -c 1045   Questions:   Is this correct behaviour, or is there a bug somewhere? If not, is this behaviour documented anywhere? Is there another parameter which defines the maximum for a single argument? Is this behaviour limited to Linux (or even particular versions of such)? What accounts for the additional ~5KB discrepancy between the actual maximum size of the argument array plus the approximate size of the environment and ARG_MAX?   Additional info:  uname -a Linux graeme-rock 3.13-1-amd64 #1 SMP Debian 3.13.5-1 (2014-03-04) x86_64 GNU/Linux
96141
What's the best way to get the last N elements of a Perl array?  If the array has less than N, I don't want a bunch of undefs in the return value.
26327
What is the easiest way to handle huge numbers in C? I need to store values in the Area 1000^900, or in more human readable form 10^2700. Does anybody know of an easy way to do that? Any help would really be appreciated!
13020
I want to initialize a struct element, split in declaration and initialization. This is what I have:  typedef struct MY_TYPE {   bool flag;   short int value;   double stuff; } MY_TYPE;  void function(void) {   MY_TYPE a;   ...   a = { true, 15, 0.123 } }   Is this the way to declare and initialize a local variable of MY_TYPE in accordance with C programming language standards (C89, C90, C99, C11, etc.)? Or is there anything better or at least working?  Update I ended up having a static initialization element where I set every subelement according to my needs.
74245
In the  book on pg 130, they mention that an Array's length is fixed when you initialize it and that multidimensional arrays are not supported. I just tried using the .add function on an array and it worked so I'm sure what they are talking about, but I couldn't make an array of arrays (which could have just been because I didn't have the right syntax). Ignoring syntax errors, there seems to be some sort of difference and thus maybe an (even if just slight) advantage to using one over the other?
7862
I want to know how to get size of objects like a string, integer, etc. in Python.  Related question:   I am using an XML file which contains size fields that specify the size of value. I must parse this XML and do my coding. When I want to change the value of a particular field, I will check the size field of that value. Here I want to compare whether the new value that I'm gong to enter is of the same size as in XML. I need to check the size of new value. In case of a string I can say its the length. But in case of int, float, etc. I am confused.
2266
In follow up to , it appears that some numbers cannot be represented by floating point at all, and instead are approximated.  How are floating point numbers stored?  Is there a common standard for the different sizes?  What kind of gotchas do I need to watch out for if I use floating point?  Are they cross-language compatible (ie, what conversions do I need to deal with to send a floating point number from a python program to a C program over TCP/IP)?
70083
I'm trying to find out how much memory my objects take to see how many of them are ending up on the  (which is anything over 85,000 bytes). Is it as simple as adding 4 for an int, 8 for a long, 4 (or 8 if you're on 64 bit) for any reference types etc for each object, or are there overheads for methods, properties, etc.?
1431
Foo* set = new Foo[100]; // ... delete [] set;   You don't pass the array's boundaries to delete[]. But where is that information stored? Is it standardised?