×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

maybe so late. but i also want to know if it's right.

const int * x means "x" is a pointer which point to a int variable, and the variable is constant.

int const* x is the same meaning as above.

The key is the syntax is: "const" always combine with the left word, forever. (so we can say in instance 2, the "const" modify the "int");
But there is a exception: when the word is a simple type such as "int", "float"( not complex like class type), the "const" can be put to the right of the word such as "const int", just like the instance 1.

so this exception make the confuse. In fact it's the same.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / Jabber's Q(2):
    C++ gurus: please enlight me. What is the
    difference between "const int* x" and "int const* x"? I aked some experts around me
    and they gave me conflicting answers.
    • maybe so late. but i also want to know if it's right.
      const int * x means "x" is a pointer which point to a int variable, and the variable is constant.

      int const* x is the same meaning as above.

      The key is the syntax is: "const" always combine with the left word, forever. (so we can say in instance 2, the "const" modify the "int");
      But there is a exception: when the word is a simple type such as "int", "float"( not complex like class type), the "const" can be put to the right of the word such as "const int", just like the instance 1.

      so this exception make the confuse. In fact it's the same.
      • Yes, they are the same....
        const int* x is easier to understand. int const* x can bring some confusion. Such things are academic. In job interviews, some interviewer like to use such things to test if the candidate really has hands-on experiences.

        Thanks for your comments.
    • 这种语法问题, 以后还识别问了吧, 层次太低了一点.
      • It looks trivial, but it's fundamental and sometimes do affect your work.
        People may not be able to remember the spelling of all the function and class names, but for the basic principle of a language, it's good to understand it thoroughly.
      • Pundit, please improve your Chinese and then post your opinion here.
        I found that your Chinese spelling is problamatic. If you really are a descent person, please show respect
        for others. By the way, if you think you are a descent person, don't post your junk in guest's name. Sorry for offending you.