English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

this is how it goes:

example()
{

short arr[20];
short I, *p;

t=arr[ I ];
p=arr + I ;

t=*p;
p=arr+I;
t=*p;

2007-08-09 07:22:14 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

I can explain them...

// declares an array of 20 shorts
short arr[20];
// declares a short and a pointer to a short
short I, *p;

// At this point, arr is a pointer to the first
// of 20 shorts -- arr[0] is the first short,
// arr[1] is the second, etc., up to arr[19].
// l is a short that is not initialized, and p
// is a pointer to a short that is not
// initialized.

// sets t to the L'th element in the array
t=arr[ I ];
// So if L=0, then T will be assigned
// whatever value is first in the array.

// sets p to the address of the L'th element
p=arr + I ;
// equivalent to: p = &(arr[l]);
// After this, *p will be the same place
// in memory as arr[l]. If you change *p,
// arr[l] will change, and vice versa.

// Sets T to the value of the short
// that P points to.
t=*p;

(The final two statements are repeated in your question.)

... but I'm not sure what you are trying to do with them.

As written, the code uses an uninitialized value (l) to index the array -- if l happens to be greater than 19 or less than 0, it'll point off into memory that it shouldn't be touching.

It also sets t = arr[l], but then t = *p where p is the address of arr[l], so it does the same thing twice, in slightly different ways.

2007-08-09 08:47:05 · answer #1 · answered by McFate 7 · 0 0

Basically, arrays are many variables, but under one variable name.

ie-
(Different language)

var = array(1-10) of integer

for x : 1 .. 10

var(x) = random(1..5)
end for

So if i wanted var(5) it will be a random number from 1 - 5.

I hope that helped... its kinda hard to explain.

2007-08-09 07:29:32 · answer #2 · answered by Anonymous · 0 0

Need more information. What exactly do you need help with?

2007-08-09 07:27:35 · answer #3 · answered by Majestic One 4 · 0 0

try http://www.ebay.ph/viItem?ItemId=330153539391

2007-08-09 08:57:36 · answer #4 · answered by eyemanga 2 · 0 1

fedest.com, questions and answers