- World's Largest Collection of Interview Questions
Start Your Own website Now
Sponsored Links

Interview Questions
Our Services

Get 9,000 Interview Questions & Answers in an eBook.

  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!

    Send your Resume to 6000 Companies

    Question :
    What is a const pointer?
    Category Operators in C Interview Questions
    Rating (0.4) By 573 users
    Added on 10/22/2004
    Views 5606
    Rate it!

    The access modifier keyword const is a promise the programmer makes to the compiler that the value of a variable will not be changed after it is initialized. The compiler will enforce that promise as best it can by not enabling the programmer to write code which modifies a variable that has been declared const.

    A ?const pointer,? or more correctly, a ?pointer to const,? is a pointer which points to data that is const
    (constant, or unchanging). A pointer to const is declared by putting the word const at the beginning of the pointer declaration. This declares a pointer which points to data that can?t be modified. The pointer itself can be modified. The following example illustrates some legal and illegal uses of a const pointer:

    const char *str = ?hello?;
    char c = *str /* legal */
    str++; /* legal */
    *str = ?a?; /* illegal */
    str[1] = ?b?; /* illegal */

    const pointer: pointer is a constant which points the address of another variable

    we can't change the pointer(or
    otherwords can't change the
    address, pointer points to)

    char c[100]="Hello";
    char d[100]="Human";
    char *const ptr=c; //ptr points c
    ptr=d;/* Illegal*/
    ptr[3]='Y'; /* Legal*/

    pointer to const: The address pointed by pointer is constand that means we can't change the const location value using pointer

    char c[100]="Hello";
    char d[100]="Human";
    const char *p=c;
    p[2]='M'; /* Illegal */
    p=d; /* Legal */


    Posted by: VENKATGOPU    


    Pointer Constant is a pointer which points to the same location everytime. The address in the pointer variable can't be changed.
    int a=10,b=20;
    int const *p=&a;
    p=&b//Illegal: p a constant pointer always points to the same location

    But, Constant pointer always points to a value which cannot change i.e. the pointer can point to any variable but the value of the variable it points to cannot change.

    int a=10,b=20;
    const int *p=&a;
    a=30;//Illegal as p is a constant pointer the value it points to cannot change

    Posted by: Samuka Mohanty    

    Contact Samuka Mohanty Contact Samuka Mohanty

    If you have the better answer, then send it to us. We will display your answer after the approval.
    Rules to Post Answers in

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

    Related Questions
    View Answer
    When should a type cast not be used?
    View Answer
    Can math operations be performed on a void pointer?
    View Answer
    What is a modulus operator? What are the restrictions of a modulus operator?
    View Answer
    Why n++ executes faster than n+1?
    View Answer

    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here - Best Freshers & Experienced Jobs Website.

    View ALL Operators in C Interview Questions

    User Options
    Sponsored Links

    Copyright ©2003-2015, All Rights Reserved.
    Privacy Policy | Terms and Conditions

    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Dedicated Servers | C Interview Questions & Answers

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

    Cache = 0.046875 Seconds