how many bytes are occupied by a an array of 100ints, is it 100*8=800, that seems wrong
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])
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
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.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
That depends on the architecture (and in some cases, the compiler) that you're working with.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.
Insert obnoxious but pithy remark here
ok what if it was a windows based sytem using a mirosoft c compiler
And 100 * sizeof(char*) or sizeof(char* [100]).Originally Posted by Dave_Sinkula
And if you mean ILP32 (Win32), then it's 400 for both examples.
Last edited by Dave_Sinkula; 01-18-2006 at 07:32 PM. Reason: Closed formatting tag.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
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.
Hope is the first step on the road to disappointment.
> 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).Originally Posted by kris_perry2k
Originally Posted by ramayana
I.E. what Quzah already posted.