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. displaying the mem address of chars + char arrays

displaying the mem address of chars + char arrays

Scheduled Pinned Locked Moved C / C++ / MFC
5 Posts 2 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.
  • U Offline
    U Offline
    User 1209385
    wrote on last edited by
    #1

    I can do the following with 'int' with ease: 1: get the address of the pointer 2: get the contents of the pointer (the address it points too) 3: get the value of the variable pointed too. int *a; int b = 'B'; cout <<"address of b (the var) = " <<&b <

    Y 1 Reply Last reply
    0
    • U User 1209385

      I can do the following with 'int' with ease: 1: get the address of the pointer 2: get the contents of the pointer (the address it points too) 3: get the value of the variable pointed too. int *a; int b = 'B'; cout <<"address of b (the var) = " <<&b <

      Y Offline
      Y Offline
      Yogesh Kshatriya
      wrote on last edited by
      #2

      Modify the code as follows. It should serv your purpose. void main(){ char *a; char b = 'B'; a = &b; cout <<"address of a = " <<&a <

      U 1 Reply Last reply
      0
      • Y Yogesh Kshatriya

        Modify the code as follows. It should serv your purpose. void main(){ char *a; char b = 'B'; a = &b; cout <<"address of a = " <<&a <

        U Offline
        U Offline
        User 1209385
        wrote on last edited by
        #3

        Can you please explain this to me: (unsigned long)(*(&a)) thanks :doh:

        Y 1 Reply Last reply
        0
        • U User 1209385

          Can you please explain this to me: (unsigned long)(*(&a)) thanks :doh:

          Y Offline
          Y Offline
          Yogesh Kshatriya
          wrote on last edited by
          #4

          a contains address of b. But if you say cout << a, it won't print the contents of a ( i.e address of b). But you know it is address i.e. unsigned long type, so force it to print conent of a as an address. Actually referencing & derefrerncing in the statment is not required. i.e (unsigned long)(*(&a)) is same as (unsigned long)(a)

          U 1 Reply Last reply
          0
          • Y Yogesh Kshatriya

            a contains address of b. But if you say cout << a, it won't print the contents of a ( i.e address of b). But you know it is address i.e. unsigned long type, so force it to print conent of a as an address. Actually referencing & derefrerncing in the statment is not required. i.e (unsigned long)(*(&a)) is same as (unsigned long)(a)

            U Offline
            U Offline
            User 1209385
            wrote on last edited by
            #5

            hmmm, yes that makes much more sense, thanks!:)

            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