tags:

views:

126

answers:

4

What is the size of this array?

float a[10];
+4  A: 

It equals sizeof a

Unless you pass it to a function :-) But +1 for being right.
paxdiablo
A: 

Have ever heard about sizeof. It must help.

Incognito
A: 

Enough to 10 floats. It depends of implementation. In most implemetations of C compilers float is 4 bytes long, so it will be at least 4 * 10 bytes. In C there is sizeof, use it!

Michał Niklas
A float is C is _not_ 4 bytes long. It _may_ be that long but it's not guaranteed by the standard.
paxdiablo
Thanks. Changed.
Michał Niklas
Doesn't C standards dictate the usage of IEEE 754 fp nums? 10*sizeof(float) is always safer and what I do, but I would have bet that float is always 4 bytes in all C standard-compliant compilers; would I have lost the bet? It seems so
ShinTakezou
A: 

Look for a C manual (sizeof keyword):

#include <stdio.h>

int main(void)
{
  float a[10];

  printf("sizeof float %d\n", sizeof(float) );
  printf("sizeof array %d\n", sizeof(a) );
  printf("array size %d\n", sizeof(a)/sizeof(a[0]) ); // sizeof(a[0]) is the same with sizeof(float)
  return 0;
}

Hope it is not too hard.

Iulian Şerbănoiu