Thread: Important question

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    11

    Cool Important question

    How can we modify a constant variable?
    suppose
    const int x=12;
    How can we change its value????
    Please tell me.
    All is well that ends well

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    17
    Specify a pointer to the variable that you want to change. That should do the trick.
    -----------------------------------------------
    everready

    To code, or not to code, that is the question.

    Well the answer is 'TO CODE' of cause

  3. #3
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Specify a pointer to the variable that you want to change
    You can only assign an address of a constant to a pointer to a constant so that wouldn't work. You can cast though -


    const int a = 10;
    const int* ptr = &a;
    *(int *)ptr=20;
    zen

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Why make it const if you are going to want to change it? You are better off just being careful not too fool with it too much.
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. important question!!!
    By brita in forum Windows Programming
    Replies: 7
    Last Post: 04-27-2003, 02:23 PM
  2. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  3. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  4. I have a Question about memory usage for C.
    By bobthefish3 in forum C Programming
    Replies: 34
    Last Post: 12-24-2001, 04:37 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM