Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. const int *

const int *

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shraddha Gautam
    wrote on last edited by
    #1

    what is meaning of const int * & int * const.

    J K Z 3 Replies Last reply
    0
    • S Shraddha Gautam

      what is meaning of const int * & int * const.

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      The difference is where the const applied; is it applied to the pointer, or what is being pointed to.  The first one is a pointer to a const int, meaning that the pointer can change (you can have the pointer point to a different int), but not what is pointed to.    Peace!

      -=- James
      Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
      See DeleteFXPFiles

      1 Reply Last reply
      0
      • S Shraddha Gautam

        what is meaning of const int * & int * const.

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #3

        const int * a constant pointer to an int int * const a int pointer to a constant int it is a little confusing. And it isnt the best way to code such thing.

        Greetings from Germany

        1 Reply Last reply
        0
        • S Shraddha Gautam

          what is meaning of const int * & int * const.

          Z Offline
          Z Offline
          zakkas2483
          wrote on last edited by
          #4

          i Think u r not clear from above two ans so i m explaing u ... Pointer To Const syntex: int const *ptr; or const int *ptr; that means they are pointer to const int. so we can't change the value of they are pointing. we can change what they r pointing.... for example: int i = 10; int b = 20; int const *ptr = & i; (*ptr)++ ; // will give error ptr = & b ; // OK Const pointer: syntex : int * const ptr1; it is const pointer so what it is pointing is const so we must initialize at the time of declaration so synetx is like int * const ptr1 = & someintegervarible; for example: int i = 10; int b = 20; int * const ptr1 = & i; //required initialization (*ptr1)++ ;//OK ptr1 = & b; // Error we also have const pointer to const : syntex : int const * const ptr2 = & i; // required initialization or const int * const ptr2 = & i; // required initialization Neither address which that pointer is pointing nor the value that pointer pointing will change. Hiren Thakkar

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups