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. Little doubts

Little doubts

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
10 Posts 8 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 1547527
    wrote on last edited by
    #1

    i got some small doubts as i am new to c++. Will u please help me to sort it out? (1)is 'int* x' same as 'int *x' (2)'char const* x' same as ‘const char *x’ Vendy

    C M G D 4 Replies Last reply
    0
    • U User 1547527

      i got some small doubts as i am new to c++. Will u please help me to sort it out? (1)is 'int* x' same as 'int *x' (2)'char const* x' same as ‘const char *x’ Vendy

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      1 - yes, whitespace is irrelevant 2 - no. one makes the pointer const, one makes it's contents const, from memory. They are not the same tho. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

      S 1 Reply Last reply
      0
      • U User 1547527

        i got some small doubts as i am new to c++. Will u please help me to sort it out? (1)is 'int* x' same as 'int *x' (2)'char const* x' same as ‘const char *x’ Vendy

        M Offline
        M Offline
        marinme
        wrote on last edited by
        #3

        -c wrote: (1)is 'int* x' same as 'int *x' it works the same, but some people prefer one over the other to remind them it is a pointer to int, not int pointer. -c wrote: (2)'char const* x' same as ‘const char *x’ char const * x;//this is a constant pointer to a char type const char * x;//this is a pointer to a constant char type

        U 1 Reply Last reply
        0
        • U User 1547527

          i got some small doubts as i am new to c++. Will u please help me to sort it out? (1)is 'int* x' same as 'int *x' (2)'char const* x' same as ‘const char *x’ Vendy

          G Offline
          G Offline
          Gary R Wheeler
          wrote on last edited by
          #4

          (1) int* x and int *x mean the same thing. (2) char const* x and const char *x do not mean the same thing. char const* x may be read as 'x is a constant pointer to char'. In this case, the pointer is constant, not the character data it points to. const char *x may be read as 'x is a pointer to characters that are constant.' For this one, the character data is constant.


          Software Zen: delete this;

          Z 1 Reply Last reply
          0
          • M marinme

            -c wrote: (1)is 'int* x' same as 'int *x' it works the same, but some people prefer one over the other to remind them it is a pointer to int, not int pointer. -c wrote: (2)'char const* x' same as ‘const char *x’ char const * x;//this is a constant pointer to a char type const char * x;//this is a pointer to a constant char type

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

            thank you guys.... one more thing.. is 'char const*' same as 'char *const'??? Vendy

            T 1 Reply Last reply
            0
            • U User 1547527

              thank you guys.... one more thing.. is 'char const*' same as 'char *const'??? Vendy

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              yes. const is only an identifier, but most use it before the type. you could verify it by yourself (and you will have too because even if you're new to VC++, this is not a "primary school forum") using sizeof()... another thing : read this[^]


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              D 1 Reply Last reply
              0
              • C Christian Graus

                1 - yes, whitespace is irrelevant 2 - no. one makes the pointer const, one makes it's contents const, from memory. They are not the same tho. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

                S Offline
                S Offline
                S Senthil Kumar
                wrote on last edited by
                #7

                I think you got it wrong, char const * x and const char *x are the same and prevent you from changing the contents. For making the pointer itself const, you need to use char * const x. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

                1 Reply Last reply
                0
                • G Gary R Wheeler

                  (1) int* x and int *x mean the same thing. (2) char const* x and const char *x do not mean the same thing. char const* x may be read as 'x is a constant pointer to char'. In this case, the pointer is constant, not the character data it points to. const char *x may be read as 'x is a pointer to characters that are constant.' For this one, the character data is constant.


                  Software Zen: delete this;

                  Z Offline
                  Z Offline
                  Zdeslav Vojkovic
                  wrote on last edited by
                  #8

                  char const* x and const char *x are the same thing, and they mean "x is a pointer to characters that are constant.'". "char * const x" means "x is a constant pointer to char"

                  1 Reply Last reply
                  0
                  • T toxcct

                    yes. const is only an identifier, but most use it before the type. you could verify it by yourself (and you will have too because even if you're new to VC++, this is not a "primary school forum") using sizeof()... another thing : read this[^]


                    TOXCCT >>> GEII power
                    [toxcct][VisualCalc]

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    toxcct wrote: read this[^] Bad link, perhaps?


                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                    1 Reply Last reply
                    0
                    • U User 1547527

                      i got some small doubts as i am new to c++. Will u please help me to sort it out? (1)is 'int* x' same as 'int *x' (2)'char const* x' same as ‘const char *x’ Vendy

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      -c wrote: (2)'char const* x' same as ‘const char *x’ See here.


                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                      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