about array and pointer

Discussion in 'Meet and Greet' started by imported_Ankit Agarwal, Apr 28, 2012.

  1. imported_Ankit Agarwal

    imported_Ankit Agarwal New Member

    Joined:
    Apr 28, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    is a[10] and *a are same to store 10 value
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    it depends; if *a points to an existing array of 10 elements, then yes. If not, then you'd need to dynamically allocate space for the 10 elements.

    Code:
    int a[10], *ap = a; // ok ap points to an existing array
    Code:
    int *a = malloc(10 * sizeof(*a)); // allocate space for 10 elements
    ...
    free(a);
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice