how many bytes are occupied by a an array of 100ints, is it 100*8=800, that seems wrong
Printable View
how many bytes are occupied by a an array of 100ints, is it 100*8=800, that seems wrong
100 * sizeof(int) or sizeof(int [100])
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"
I posted the C answer for the array of ints. It is done similarly for an array of pointers.
That depends on the architecture (and in some cases, the compiler) that you're working with.Quote:
Originally Posted by kris_perry2k
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.
ok what if it was a windows based sytem using a mirosoft c compiler
And 100 * sizeof(char*) or sizeof(char* [100]).Quote:
Originally Posted by Dave_Sinkula
And if you mean ILP32 (Win32), then it's 400 for both examples.
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.
> 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.
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).Quote:
Originally Posted by kris_perry2k
Quote:
Originally Posted by ramayana
I.E. what Quzah already posted.