小编yet*_*oob的帖子

我对指针/引用中C++中"&"运算符的不一致应用感到困惑?

我已经检查了很多编程语言(Java,Erlang,python等)但我发现C/C++很难学习.仅仅因为我认为它有时候不合理;

EX1:

    #include <iostream>

    int main() {

     int ar1 = {1,2,3};
     int *p1 = ar1;

     char *msg = "message";

     std::cout << "addr: " << p1 << std::endl ;//prints the array address

     std::cout << "value: " << *p1 << std::endl ;//prints the first element


     std::cout << "addr: " << msg << std::endl ;//prints "message" , wtf why not    the addr?how can i get its address?

     std::cout << "value: " << *msg << std::endl ;//prints the first character


    }
Run Code Online (Sandbox Code Playgroud)

EX2:

    #include <iostream> …
Run Code Online (Sandbox Code Playgroud)

c++ pointers reference

-4
推荐指数
1
解决办法
162
查看次数

标签 统计

c++ ×1

pointers ×1

reference ×1