我检查了许多编程语言(Java、Erlang、python 等),但我发现 C/C++ 很难学习。仅仅是因为我有时认为它不合理;
例1:
#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
}
例 2:
#include <iostream>
int main() {
int n1 = 5;
int *p1 = &n1;
int &r1 = *p1; // why not: int &r1 = p1; ,*p1 is NOT an address,p1 is.This does not make any sense...
}
你能给我解释一下这些例子吗?如果不解决这些问题,我就无法继续学习 Cplusplus。
谢谢你的时间。