Results 1 to 6 of 6

Thread: Difference between following declarations

  1. #1
    Moderator
    Join Date
    Oct 2005
    Answers
    305

    Difference between following declarations

    What is the difference between the following declarations?

    const char *s;
    char const *s;

    Please mention it briefly.


    NOTE : [This question was asked by Dhananjaya Mohanty]


  2. #2
    Expert Member
    Join Date
    Dec 2006
    Answers
    204

    Re: Difference between following declarations

    const char *s;
    This declares a constant data and a variable pointer.
    char const *s;
    This is invalid i think. I should look like:
    char * const s;
    This declares a variable data and a constant pointer.
    const char * const s;
    This declares a constant data and constant pointer.


  3. #3
    Administrator
    Join Date
    May 2006
    Answers
    331

    Re: Difference between following declarations

    The two declarations namely

    const char *s;
    and
    char const *s;

    are not equivalent.

    In the first statement namely
    const char *s;
    the char is constant.

    But in the second statement namely
    char const *s;
    the pointer itself is const. So in this it is not possible to change the pointer using any of the
    pointer arithmetic say as s++.


  4. #4
    Junior Member
    Join Date
    Nov 2006
    Answers
    5

    Re: Difference between following declarations

    char const *s;
    the pointer itself is const. So in this it is not possible to change the pointer using any of the
    pointer arithmetic say as s++.


  5. #5
    Moderator
    Join Date
    Oct 2005
    Answers
    305

    Re: Difference between following declarations

    Barbie and Admin, Thanks for your answers

    nitin.pathak Thanks for you also, your answer is same as last part of admin answer


  6. #6
    Contributing Member
    Join Date
    Jul 2006
    Answers
    57

    Re: Difference between following declarations

    Very interesting question and answer on pointer concepts. Friends thanks for such useful posts.


  7.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact