# Bytes

This is a discussion on Bytes within the C Programming forums, part of the General Programming Boards category; how many bytes are occupied by a an array of 100ints, is it 100*8=800, that seems wrong...

1. ## Bytes

how many bytes are occupied by a an array of 100ints, is it 100*8=800, that seems wrong

2. 100 * sizeof(int) or sizeof(int [100])

3. yeah thats what i thought, it would depend on the size of the int. But this is what ive been asked

"in C, how many bytes of memory are occupied by an array of 100ints and an array of 100 character pointers"

4. I posted the C answer for the array of ints. It is done similarly for an array of pointers.

5. Originally Posted by kris_perry2k
"in C, how many bytes of memory are occupied by an array of 100ints and an array of 100 character pointers"
That depends on the architecture (and in some cases, the compiler) that you're working with.

I've worked on machines where sizeof(int) = 2, and sizeof(char *) = 2; I've worked on others where sizeof(int) = 4 and sizeof(char *) = 4, and one machine where sizeof(char *) = 8... Then there was the compiler for the embedded processor that had sizeof(int) = 4, but sizeof(char *) = 2.

So there is no single correct numeric answer.

6. ok what if it was a windows based sytem using a mirosoft c compiler

7. Originally Posted by Dave_Sinkula
100 * sizeof(int) or sizeof(int [100])
And 100 * sizeof(char*) or sizeof(char* [100]).

And if you mean ILP32 (Win32), then it's 400 for both examples.

8. It depends on the compiler. Do you have a 16 bit compiler? A 32 bit compiler? See. This is why there is no one number answer that is correct. The true "correct" answer is:

"It depends on the OS, and compiler."

Quzah.

9. > ok what if it was a windows based sytem using a mirosoft c compiler
Write your own program to print the result of various sizeof calculations.

10. Originally Posted by kris_perry2k
how many bytes are occupied by a an array of 100ints, is it 100*8=800, that seems wrong
An integer(default in type) type occupies the whole word length of a computer as it's storage . Hence , for a 16 bit computer(my case) one integer occupies 16 bits or convinently 2 bytes. For an array of 100 integers the memory occupied would be 100*word length of computer (200 bytes in my case).

11. Originally Posted by ramayana
An integer(default in type) type occupies the whole word length of a computer as it's storage . Hence , for a 16 bit computer(my case) one integer occupies 16 bits or convinently 2 bytes. For an array of 100 integers the memory occupied would be 100*word length of computer (200 bytes in my case).