Thread: Changing constant value by pointer variable

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    34

    Changing constant value by pointer variable

    Hi guys.
    I'm wondering if it's possible that when I declare an constant value and I point to it by pointer variable (not constant pointer variable) ... is it legible and possible to change the value that Im pointing at?

    I mean for example lets assume
    Code:
     const int var=10
    so if I point to this value by integer pointer variable (not constant pointer) will the value that Im pointing at (the value var) change?


    another question in the same context, if I have pointer variable which it's constant (i.e like
    Code:
     int const *ptr
    ) so I can't change the value that ptr is pointing at
    by ptr pointer, but I can declare another pointer variable like int *ptr2 and let it points to the
    same value and then I can change the value by ptr2 pointer .. right?
    in other words
    Code:
     int const *ptr
    is a constant regarding to ptr itself but I can declare another
    pointer variable which it's not const and change the value that ptr pointing at by
    the new pointer variable .. right?
    Last edited by JohnnyOmari; 12-09-2020 at 02:30 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about constant variable in c/c++
    By fatshaw in forum C++ Programming
    Replies: 2
    Last Post: 12-16-2010, 10:16 PM
  2. constant being treated as 32-bit when variable is 64-bit
    By ulillillia in forum C Programming
    Replies: 12
    Last Post: 08-13-2010, 12:07 AM
  3. Constant Being Initialized AFTER Variable That Uses It
    By mercury529 in forum C++ Programming
    Replies: 22
    Last Post: 07-30-2006, 09:51 AM
  4. Changing a variable to a constant.
    By esben in forum C Programming
    Replies: 6
    Last Post: 03-22-2006, 06:29 AM
  5. Constant pointer to constant value
    By tretton in forum C Programming
    Replies: 10
    Last Post: 12-23-2005, 01:45 PM

Tags for this Thread