Saturday, January 7, 2012

character array vs character pointers

Discuss the facts regarding character arrays a[] & character pointers *a.Also explain the relevant operations that can be performed on these two.

2 comments:

  1. char amessage[]="now is the time";
    char *pmessage= "now is the time";

    amessage is
    1)an array just big enough to hold the sequence of characters and '\0' that initialises it
    2)Individual characters within the array may be changed but amessage will always refer to the same storage i.e. amessage cant point to some other location;so incrementing and decrementing it is not allowed

    pmessage is
    1)a pointer initialised to point to a string constant storage in read only area
    2)The pointer may be modified to point elsewhere;but the result is undefined is we try to modify string constants.

    ReplyDelete
  2. http://techblog.rosedu.org/arrays-vs-pointers.html

    ReplyDelete