On Fri, 26 Mar 1999, Amol Mohite wrote:

# say I have a char *c pointing to an array of 10 bytes.

you mean:

char myarray[10], *c;

c = myarray;

# When i do (int *)c++ (increment before typecast -- forget the brackets for
# nw), and equate it t  an int *i then

please re-read what you type. this is full of typos and makes it really
difficult to read. Also include example code as it makes it more clear.

(int *)c++; doesn't do much except make c point at myarray[1] and return
the value typecast as an int (thus returning the character's ascii code).
 
# *i will return 2nd to fifth bytes as integer. Is this correct ?

no, first make i point to the array. typecasting in that way doesn't
convert the types of the elements in that array. To get the 2nd -> 5th
bytes (elements) as integers you'd have to:

int cnt;

for (cnt = 1; cnt < 5; cnt++)
        printf ("%d\n", (int *)(c+cnt)); /* you have to do something with */
                                         /* the typecast variables */

except why bother with pointers to array elements?

for (cnt = 1; cnt < 5; cnt++)
        printf ("%d\n", (int *)myarray[cnt]);

# And supose the typecase is beore the incerenent like so :
# ((int *)c)++ then *i will return 5th to 8th byes. is this correct ?

no. that would cast c to an integer and then return the next one, which is
of type char.
 
 
# aslo how is exception handling implemented ? Does the processor have
# exception registers ?

what do you mean by exceptions? things like running out of memory and
opening non-existant files, etc? to deal with these the functions that
do the file i/o, memory allocation, whatever. return values that you
check.
 
# Also if I have allocated a struct liek :
# 
# struct {
#       int i;
#       char b;
# }str;
# 
# which is obviously 5 butes large.

not always. it will be

sizeof (int) + sizeof (char)

which on my machine (P233) is 5 bytes. Someone running a Sun or Alpha may have
different sized variables.
 
# Than whenre will the proceessor allocate the next bit of memory ?
# Directly after the char b byte?

it doesn't matter where it goes. All you need to know, as a C programmer,
is that you have some struct called str which contains an integer and a
character.

Do you own a good C book? (the Kernighan & Ritchie ANSI C Programming Book
is a good one. Ones that mention Turbo C, or other DOS things, aren't - for
Linux programming that is)

-- 
+++      If at first you don't succeed, you must be a programmer     +++
[EMAIL PROTECTED]     http://www.users.globalnet.co.uk/~kermit

Reply via email to