assigning array addresses to integer variables and vice versa

Discussion in 'C Programming' started by anonymous, Nov 24, 2005.

  1. anonymous

    anonymous Guest

    I have couple of questions related to array addresses. As they belong
    to the same block, I
    am putting them here in one single post. I hope nobody minds:

    char array[35];

    int address;

    Questions 1:
    Why cannot I do the following:

    address = (int)array;

    whereas I found it perfectly alright to do the following:

    address = (int)&array;

    Question 2:
    What is the difference between array and &array. Are not they the same
    thing i.e. starting
    address of the array.

    Question 3:

    Why cannot I do array++. Is array a pointer constant?

    Question 4:
    How can I do the following:

    array = address;

    i.e. Give a new starting address to the array. Is it possible?

    Thanks in advance for all Your replies.

    A.
     
    anonymous, Nov 24, 2005
    #1
    1. Advertising

  2. anonymous

    pemo Guest

    "anonymous" <> wrote in message
    news:...
    >I have couple of questions related to array addresses. As they belong
    > to the same block, I
    > am putting them here in one single post. I hope nobody minds:
    >
    > char array[35];
    >
    > int address;
    >
    > Questions 1:
    > Why cannot I do the following:
    >
    > address = (int)array;
    >
    > whereas I found it perfectly alright to do the following:
    >
    > address = (int)&array;
    >
    > Question 2:
    > What is the difference between array and &array. Are not they the same
    > thing i.e. starting
    > address of the array.
    >
    > Question 3:
    >
    > Why cannot I do array++. Is array a pointer constant?
    >
    > Question 4:
    > How can I do the following:
    >
    > array = address;
    >
    > i.e. Give a new starting address to the array. Is it possible?
    >
    > Thanks in advance for all Your replies.


    >Questions 1:
    >Why cannot I do the following:


    >address = (int)array;


    What do you by 'can't do'?


    > Question 2:
    > What is the difference between array and &array. Are not they the same
    > thing i.e. starting


    an array name decomposes into the address of its first element, i.e., a
    constant. You obviously cannot take the address of a 'value', and so &array
    doesn't make sense, and I assume the compiler's saying to itself 'well, ok,
    I know what he means'.


    > Question 3:
    >
    > Why cannot I do array++. Is array a pointer constant?


    Because an array name decomposes into the address of its first element, so
    it's like saying 42++;


    > Question 4:
    > How can I do the following:
    >
    > array = address;



    You can't, it'd be like saying 42 = 24;
     
    pemo, Nov 24, 2005
    #2
    1. Advertising

  3. anonymous wrote:
    > I have couple of questions related to array addresses. As they belong
    > to the same block, I
    > am putting them here in one single post. I hope nobody minds:
    >
    > char array[35];
    >
    > int address;
    >
    > Questions 1:
    > Why cannot I do the following:
    >
    > address = (int)array;


    No, it is a legal syntax. However pointer to integer conversion may
    invoke undefined behavior if result cannot be represented in integer
    type.

    >
    > whereas I found it perfectly alright to do the following:
    >
    > address = (int)&array;
    >
    > Question 2:
    > What is the difference between array and &array. Are not they the same
    > thing i.e. starting
    > address of the array.


    array and &array are same in value context, both yield pointer to
    first element in value context.

    >
    > Question 3:
    >
    > Why cannot I do array++. Is array a pointer constant?


    postfix increment operator needs a modifiable l-value. array name is
    not a modifiable l-value.

    >
    > Question 4:
    > How can I do the following:
    >
    > array = address;
    >
    > i.e. Give a new starting address to the array. Is it possible?


    No, see above.

    Krishanu
     
    Krishanu Debnath, Nov 24, 2005
    #3
  4. anonymous

    anonymous Guest

    pemo wrote:
    > "anonymous" <> wrote in message
    > news:...
    > >I have couple of questions related to array addresses. As they belong
    > > to the same block, I
    > > am putting them here in one single post. I hope nobody minds:
    > >
    > > char array[35];
    > >
    > > int address;
    > >
    > > Questions 1:
    > > Why cannot I do the following:
    > >
    > > address = (int)array;
    > >


    > > whereas I found it perfectly alright to do the following:
    > >
    > > address = (int)&array;
    > >
    > > Question 2:
    > > What is the difference between array and &array. Are not they the same
    > > thing i.e. starting
    > > address of the array.
    > >
    > > Question 3:
    > >
    > > Why cannot I do array++. Is array a pointer constant?
    > >
    > > Question 4:
    > > How can I do the following:
    > >
    > > array = address;
    > >
    > > i.e. Give a new starting address to the array. Is it possible?
    > >
    > > Thanks in advance for all Your replies.

    >
    > >Questions 1:
    > >Why cannot I do the following:

    >
    > >address = (int)array;

    >
    > What do you by 'can't do'?


    Ooops, checking again, it is perfectly alright to do
    address = (int)array;
    My fault somewhere.
    >
    > > Question 2:
    > > What is the difference between array and &array. Are not they the same
    > > thing i.e. starting

    >
    > an array name decomposes into the address of its first element, i.e., a
    > constant. You obviously cannot take the address of a 'value', and so &array
    > doesn't make sense, and I assume the compiler's saying to itself 'well, ok,
    > I know what he means'.


    Why so liberty here when it keeps complaining all other times. I mean
    the compiler :)
    >
    >
    > > Question 3:
    > >
    > > Why cannot I do array++. Is array a pointer constant?

    >
    > Because an array name decomposes into the address of its first element, so
    > it's like saying 42++;
    >
    >
    > > Question 4:
    > > How can I do the following:
    > >
    > > array = address;

    >
    >
    > You can't, it'd be like saying 42 = 24;


    Thanks for your help.
     
    anonymous, Nov 24, 2005
    #4
  5. anonymous

    Anand Guest

    anonymous wrote:
    > I have couple of questions related to array addresses. As they belong
    > to the same block, I
    > am putting them here in one single post. I hope nobody minds:
    >
    > char array[35];
    >
    > int address;
    >
    > Questions 1:
    > Why cannot I do the following:
    >
    > address = (int)array;
    >
    > whereas I found it perfectly alright to do the following:
    >
    > address = (int)&array;
    >
    > Question 2:
    > What is the difference between array and &array. Are not they the same
    > thing i.e. starting
    > address of the array.
    >
    > Question 3:
    >
    > Why cannot I do array++. Is array a pointer constant?
    >
    > Question 4:
    > How can I do the following:
    >
    > array = address;
    >
    > i.e. Give a new starting address to the array. Is it possible?
    >
    > Thanks in advance for all Your replies.
    >
    > A.
    >

    Search this group for numerous discussion about hazels of converting int
    to pointer.

    Standard has added special type intptr_t and uintptr_t to enable integer
    types to hold object pointers.
    Discussed in section:
    "7.18.1.4 Integer types capable of holding object pointers".

    But this is a *nice to have*, your compiler can decide not implement
    this data type.

    Again, this is only for the conversion from/to void.


    To answer your specific questions.
    Q1: Both are undefined behavior

    Q2: Both means the same i.e. address of the first element.
    [ However the moment you pass an array to a function, the meaning
    changes, and hence meaning of array and &array differs there ]

    Q3&Q4: array is not an lvalue, see section:
    6.3.2.1 Lvalues, arrays, and function designators
    So you cannot modify it.
    ( Again the meaning of array changes the moment you pass it to
    function)

    --
    (Welcome) http://www.ungerhu.com/jxh/clc.welcome.txt
    (clc FAQ) http://www.eskimo.com/~scs/C-faq/top.html
     
    Anand, Nov 24, 2005
    #5
  6. anonymous

    Suman Guest

    pemo wrote:
    > "anonymous" <> wrote in message
    > news:...

    [snip]
    > > Question 2:
    > > What is the difference between array and &array. Are not they the same
    > > thing i.e. starting

    >
    > an array name decomposes into the address of its first element, i.e., a
    > constant.
    >

    [snip]

    Well, almost.

    > You obviously cannot take the address of a 'value', and so &array
    > doesn't make sense, and I assume the compiler's saying to itself 'well, ok,
    > I know what he means'.


    In a value context, an object of type "array N of T" becomes
    a value of type "pointer to T", pointing to the first element
    of that array, i.e., the one with subscript 0.

    And do search the archives.
     
    Suman, Nov 24, 2005
    #6
  7. anonymous

    anonymous Guest

    Anand wrote:
    > anonymous wrote:
    > > I have couple of questions related to array addresses. As they belong
    > > to the same block, I
    > > am putting them here in one single post. I hope nobody minds:
    > >
    > > char array[35];
    > >
    > > int address;
    > >
    > > Questions 1:
    > > Why cannot I do the following:
    > >
    > > address = (int)array;
    > >
    > > whereas I found it perfectly alright to do the following:
    > >
    > > address = (int)&array;
    > >
    > > Question 2:
    > > What is the difference between array and &array. Are not they the same
    > > thing i.e. starting
    > > address of the array.
    > >
    > > Question 3:
    > >
    > > Why cannot I do array++. Is array a pointer constant?
    > >
    > > Question 4:
    > > How can I do the following:
    > >
    > > array = address;
    > >
    > > i.e. Give a new starting address to the array. Is it possible?
    > >
    > > Thanks in advance for all Your replies.
    > >
    > > A.
    > >

    > Search this group for numerous discussion about hazels of converting int
    > to pointer.
    >
    > Standard has added special type intptr_t and uintptr_t to enable integer
    > types to hold object pointers.
    > Discussed in section:
    > "7.18.1.4 Integer types capable of holding object pointers".
    >
    > But this is a *nice to have*, your compiler can decide not implement
    > this data type.
    >
    > Again, this is only for the conversion from/to void.


    I think no compiler has it implemented as yet ? Is this so?
    >
    >
    > To answer your specific questions.
    > Q1: Both are undefined behavior
    >
    > Q2: Both means the same i.e. address of the first element.
    > [ However the moment you pass an array to a function, the meaning
    > changes, and hence meaning of array and &array differs there ]


    Can you be more elaborate on this please?

    >
    > Q3&Q4: array is not an lvalue, see section:
    > 6.3.2.1 Lvalues, arrays, and function designators
    > So you cannot modify it.
    > ( Again the meaning of array changes the moment you pass it to
    > function)
    >
    > --
    > (Welcome) http://www.ungerhu.com/jxh/clc.welcome.txt
    > (clc FAQ) http://www.eskimo.com/~scs/C-faq/top.html


    Can I get a copy of the standard for download from somewhere?

    Thanks in advance!
     
    anonymous, Nov 24, 2005
    #7
  8. anonymous

    Flash Gordon Guest

    Suman wrote:
    > pemo wrote:
    >> "anonymous" <> wrote in message
    >> news:...

    > [snip]
    >>> Question 2:
    >>> What is the difference between array and &array. Are not they the same
    >>> thing i.e. starting

    >> an array name decomposes into the address of its first element, i.e., a
    >> constant.
    >>

    > [snip]
    >
    > Well, almost.
    >
    >> You obviously cannot take the address of a 'value', and so &array
    >> doesn't make sense, and I assume the compiler's saying to itself 'well, ok,
    >> I know what he means'.

    >
    > In a value context, an object of type "array N of T" becomes
    > a value of type "pointer to T", pointing to the first element
    > of that array, i.e., the one with subscript 0.


    Not when it is the operand of either sizeof or the unary &, then it does
    *not* degenerate to a pointer. So the type of &array is pointer to
    array, where as the type of pointer array degenerates to is pointer to
    T. So they are different types.

    > And do search the archives.


    Also check the FAQ where it will be far easier to find the correct
    information.
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, Nov 24, 2005
    #8
  9. anonymous

    Flash Gordon Guest

    Krishanu Debnath wrote:
    > anonymous wrote:
    >> I have couple of questions related to array addresses. As they belong
    >> to the same block, I
    >> am putting them here in one single post. I hope nobody minds:
    >>
    >> char array[35];
    >>
    >> int address;


    <snip>

    >> Question 2:
    >> What is the difference between array and &array. Are not they the same
    >> thing i.e. starting
    >> address of the array.

    >
    > array and &array are same in value context, both yield pointer to
    > first element in value context.


    No, they have different types. &array has the type pointer to array of
    35 char, where as array degenerates to a pointer to char.

    Check the comp.lang.c FAQ

    <snip>
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, Nov 24, 2005
    #9
  10. anonymous

    Flash Gordon Guest

    anonymous wrote:
    > Anand wrote:
    >> anonymous wrote:
    >>> I have couple of questions related to array addresses. As they belong
    >>> to the same block, I
    >>> am putting them here in one single post. I hope nobody minds:
    >>>
    >>> char array[35];
    >>>
    >>> int address;
    >>>
    >>> Questions 1:
    >>> Why cannot I do the following:
    >>>
    >>> address = (int)array;
    >>>
    >>> whereas I found it perfectly alright to do the following:
    >>>
    >>> address = (int)&array;
    >>>
    >>> Question 2:
    >>> What is the difference between array and &array. Are not they the same
    >>> thing i.e. starting
    >>> address of the array.


    <snip>

    >> Q2: Both means the same i.e. address of the first element.
    >> [ However the moment you pass an array to a function, the meaning
    >> changes, and hence meaning of array and &array differs there ]

    >
    > Can you be more elaborate on this please?


    It's not quite right. &array is always different from array, they differ
    in type. So, given your definition above, the compiler *must* complain
    if you pass &array to a function with a prototype in scope specifying a
    pointer to char. E.g.

    #include <string.h>
    int main(void)
    {
    char array[35] = "hello";
    size_t len1 = strlen(array); /* this is allowed */
    size_t len2 = strlen(&array); /* The compiler is required to complain */
    }

    &array has type pointer to array, where as array otherwise degenerates
    to a pointer to char.

    >> Q3&Q4: array is not an lvalue, see section:
    >> 6.3.2.1 Lvalues, arrays, and function designators
    >> So you cannot modify it.
    >> ( Again the meaning of array changes the moment you pass it to
    >> function)
    >>
    >> --
    >> (Welcome) http://www.ungerhu.com/jxh/clc.welcome.txt
    >> (clc FAQ) http://www.eskimo.com/~scs/C-faq/top.html

    >
    > Can I get a copy of the standard for download from somewhere?


    Google for n1124 and you will find the draft for C99 + all the
    subsequent corrections. That and all the other publicly available copies
    are at http://www.open-std.org/jtc1/sc22/wg14/www/docs/ or you can buy a
    copy of the actual release version.

    I think though that you really need to work through a good text book
    though, such as K&R2, and also read the FAQ (the URL is above) which
    will tell you what K&R2 is (in the Bibliography, I think).
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, Nov 24, 2005
    #10
  11. anonymous

    Eric Sosman Guest

    anonymous wrote:

    > I have couple of questions related to array addresses. As they belong
    > to the same block, I
    > am putting them here in one single post. I hope nobody minds:
    >
    > char array[35];
    >
    > int address;
    >
    > Questions 1:
    > Why cannot I do the following:
    >
    > address = (int)array;


    You can, if you like. The result will be useful on
    some machines, useless on others. I wouldn't recommend it.

    > whereas I found it perfectly alright to do the following:
    >
    > address = (int)&array;


    That's equally legitimate, equally useful or useless.
    Again, I wouldn't recommend it.

    > Question 2:
    > What is the difference between array and &array. Are not they the same
    > thing i.e. starting
    > address of the array.


    This is Question 6.12 in the comp.lang.c Frequently Asked
    Questions (FAQ) list

    http://www.eskimo.com/~scs/C-faq/top.html

    > Question 3:
    >
    > Why cannot I do array++. Is array a pointer constant?


    FAQ Question 6.7.

    > Question 4:
    > How can I do the following:
    >
    > array = address;
    >
    > i.e. Give a new starting address to the array. Is it possible?


    No.

    > Thanks in advance for all Your replies.


    You're welcome. Read the FAQ; it will do you good.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Nov 24, 2005
    #11
  12. anonymous

    Eric Sosman Guest

    Krishanu Debnath wrote:

    > array and &array are same in value context, both yield pointer to
    > first element in value context.


    They are not the same. Both produce pointers, but
    point to different objects. Please read the FAQ.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Nov 24, 2005
    #12
  13. anonymous

    Jordan Abel Guest

    On 2005-11-24, Eric Sosman <> wrote:
    > Krishanu Debnath wrote:
    >
    >> array and &array are same in value context, both yield pointer to
    >> first element in value context.

    >
    > They are not the same. Both produce pointers, but
    > point to different objects. Please read the FAQ.


    They will compare equal, though, if converted to a void *

    [because they point to the same memory location]
     
    Jordan Abel, Nov 24, 2005
    #13
  14. Anand <> writes:
    > anonymous wrote:
    >> I have couple of questions related to array addresses. As they belong
    >> to the same block, I
    >> am putting them here in one single post. I hope nobody minds:
    >> char array[35];
    >> int address;
    >> Questions 1:
    >> Why cannot I do the following:
    >> address = (int)array;
    >> whereas I found it perfectly alright to do the following:
    >> address = (int)&array;
    >> Question 2:
    >> What is the difference between array and &array. Are not they the same
    >> thing i.e. starting
    >> address of the array.
    >> Question 3:
    >> Why cannot I do array++. Is array a pointer constant?
    >> Question 4:
    >> How can I do the following:
    >> array = address;
    >> i.e. Give a new starting address to the array. Is it possible?
    >> Thanks in advance for all Your replies.
    >> A.
    >>

    > Search this group for numerous discussion about hazels of converting
    > int to pointer.
    >
    > Standard has added special type intptr_t and uintptr_t to enable
    > integer types to hold object pointers.
    > Discussed in section:
    > "7.18.1.4 Integer types capable of holding object pointers".
    >
    > But this is a *nice to have*, your compiler can decide not implement
    > this data type.
    >
    > Again, this is only for the conversion from/to void.
    >
    >
    > To answer your specific questions.
    > Q1: Both are undefined behavior


    Converting a pointer to an integer *can* invoke undefined behavior.
    Specifically:

    Any pointer type may be converted to an integer type. Except as
    previously specified, the result is implementation-defined. If the
    result cannot be represented in the integer type, the behavior is
    undefined. The result need not be in the range of values of any
    integer type.

    > Q2: Both means the same i.e. address of the first element.
    > [ However the moment you pass an array to a function, the meaning
    > changes, and hence meaning of array and &array differs there ]


    As others have pointed out, they're not the same; they have different
    types.

    There's nothing special about function calls. An array expression is
    implicitly converted to a pointer to its first element in *any*
    context other than as the operand of a unary "&" or "sizeof", or when
    it's a string literal in an initializer.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Nov 24, 2005
    #14
  15. anonymous

    Jordan Abel Guest

    On 2005-11-24, Keith Thompson <> wrote:
    >> Q2: Both means the same i.e. address of the first element.
    >> [ However the moment you pass an array to a function, the meaning
    >> changes, and hence meaning of array and &array differs there ]

    >
    > As others have pointed out, they're not the same; they have different
    > types.
    >
    > There's nothing special about function calls. An array expression is
    > implicitly converted to a pointer to its first element in *any*
    > context other than as the operand of a unary "&" or "sizeof", or when
    > it's a string literal in an initializer.


    well, there _is_ one thing special about functions, but it pertains to
    function prototypes, not funtion calls: the fact that declaring what
    appears to be an array formal parameter is in fact a pointer formal
    parameter [and thus, int main(int argc, char *argv[5]); is compatible
    with int main(int argc, char **argv);, and sizeof argv == sizeof(char
    **) in both cases, and not 5*sizeof(char *).]
     
    Jordan Abel, Nov 24, 2005
    #15
  16. anonymous

    Randy Howard Guest

    anonymous wrote
    (in article
    <>):

    > I have couple of questions related to array addresses.


    [snip]

    What you are trying to do is going to cause you a lot of grief
    in the long run. Do not make assumptions about the size of a
    pointer being equivalent to the size of some other data type,
    unless you are 100% sure that your code does not need to be
    portable off-platform, including moving from 32-bit to 64-bit
    environments. If you wish to pursue this, it's not appropriate
    for comp.lang.c, which discusses standard C and portable
    programming within that scope.

    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw
     
    Randy Howard, Nov 24, 2005
    #16
  17. On 24 Nov 2005 04:00:21 -0800, "anonymous" <> wrote:

    >I have couple of questions related to array addresses. As they belong
    >to the same block, I
    >am putting them here in one single post. I hope nobody minds:
    >
    >char array[35];
    >
    >int address;
    >
    >Questions 1:


    Others have answered

    >Question 2:


    Ditto

    >Question 3:
    >
    >Why cannot I do array++. Is array a pointer constant?


    array is not a pointer at all. To prove this to yourself, print the
    sizeof array as well as the sizeof several different types of
    pointers. sizeof array must be 35 while sizeof(T*) for various types T
    will usually be 4 or 8, depending on your system.

    It is true that in certain circumstances an unsubscripted array name
    in an expression will **evaluate to** the address of the first element
    of the array with type pointer to element type but:

    It does not create a pointer object in the same sense that a
    definition such as "char *ptr;" does.

    The resulting value is not a modifiable lvalue and cannot be the
    operand of prefix or postfix ++.

    >
    >Question 4:
    >How can I do the following:
    >
    >array = address;
    >
    >i.e. Give a new starting address to the array. Is it possible?


    Not at all. And why would you ever want to? If you want to change
    the contents of an entire array, you can use memcpy. If you want the
    same code to process different arrays, you can use pointers.


    <<Remove the del for email>>
     
    Barry Schwarz, Nov 24, 2005
    #17
  18. anonymous

    Eric Sosman Guest

    Jordan Abel wrote:
    > On 2005-11-24, Eric Sosman <> wrote:
    >
    >>Krishanu Debnath wrote:
    >>
    >>
    >>>array and &array are same in value context, both yield pointer to
    >>>first element in value context.

    >>
    >> They are not the same. Both produce pointers, but
    >>point to different objects. Please read the FAQ.

    >
    >
    > They will compare equal, though, if converted to a void *
    >
    > [because they point to the same memory location]


    True, but not particularly relevant. 0 == 0LL, but
    that doesn't mean that `int' and `long long' are the same.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Nov 24, 2005
    #18
  19. On 24 Nov 2005 04:00:21 -0800, "anonymous" <> wrote:

    >I have couple of questions related to array addresses. As they belong
    >to the same block, I
    >am putting them here in one single post. I hope nobody minds:
    >
    >char array[35];
    >
    >int address;
    >
    >Questions 1:


    Others have answered

    >Question 2:


    Ditto

    >Question 3:
    >
    >Why cannot I do array++. Is array a pointer constant?


    array is not a pointer at all. To prove this to yourself, print the
    sizeof array as well as the sizeof several different types of
    pointers. sizeof array must be 35 while sizeof(T*) for various types T
    will usually be 4 or 8, depending on your system.

    It is true that in certain circumstances an unsubscripted array name
    in an expression will **evaluate to** the address of the first element
    of the array with type pointer to element type but:

    It does not create a pointer object in the same sense that a
    definition such as "char *ptr;" does.

    The resulting value is not a modifiable lvalue and cannot be the
    operand of prefix or postfix ++.

    >
    >Question 4:
    >How can I do the following:
    >
    >array = address;
    >
    >i.e. Give a new starting address to the array. Is it possible?


    Not at all. And why would you ever want to? If you want to change
    the contents of an entire array, you can use memcpy. If you want the
    same code to process different arrays, you can use pointers.


    <<Remove the del for email>>
     
    Barry Schwarz, Nov 24, 2005
    #19
  20. On 24 Nov 2005 04:00:21 -0800, in comp.lang.c , "anonymous"
    <> wrote:

    >I have couple of questions related to array addresses. As they belong
    >to the same block, I
    >am putting them here in one single post. I hope nobody minds:
    >
    >char array[35];
    >
    >int address;
    >
    >Questions 1:
    >Why cannot I do the following:
    >
    >address = (int)array;


    Because its nonsensical. How can you convert an array to an integer?

    >
    >whereas I found it perfectly alright to do the following:
    >
    >address = (int)&array;


    This is equally nonsensical. Your compiler won't complain though,
    because this time the conversion is allowed - you're converting a
    pointer to an array into an int. Its just a nonsensical conversion.

    >Question 2:
    >What is the difference between array and &array.


    Array is the array. &array is the address of the start of array.

    >Are not they the same
    >thing i.e. starting address of the array.


    They have different types, even though they may refer to the same
    memory location.

    >Question 3:
    >
    >Why cannot I do array++. Is array a pointer constant?


    An array is an array. Its NOT a pointer.

    >Question 4:
    >How can I do the following:
    >
    >array = address;
    >
    >i.e. Give a new starting address to the array. Is it possible?


    No. An array is an array. if you want a pointer, use a pointer.

    And please read the FAQ, there's a big section about pointers.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Nov 24, 2005
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. carmen
    Replies:
    4
    Views:
    30,809
    ersecchio
    Jan 12, 2010
  2. Tim  Wong
    Replies:
    5
    Views:
    21,994
    Tim Wong
    Jan 21, 2005
  3. rz0
    Replies:
    4
    Views:
    483
  4. FPGA
    Replies:
    5
    Views:
    1,321
    Thomas Stanka
    Jan 8, 2008
  5. Peter Otten
    Replies:
    1
    Views:
    169
    Andreas Perstinger
    Jun 18, 2013
Loading...

Share This Page