+ Reply to Thread
Results 1 to 2 of 2

Thread: Can I change value of the *p where p is const int?

  1. #1

    Can I change value of the *p where p is const int?

    Can I change value of the *p where p is "const int"?

  2. #2
    No, you cannot change the value pointed to by such a pointer.

    Example:

    Code:
    void UseConst()
    {
    	int nValue1 = 10 ;
    	const int *pConst = &nValue1 ;
    	//*pConst = 42 ; //error C2166: l-value specifies const object
    
    	int nValue2 = 42 ;
    	pConst = &nValue2 ;
    }
    Note:
    You can change the address of the pointer which can have different value as described in above example!

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts