<span style="font-size:24px;">#include<iostream>
using std ::cout;
using std ::string;
using std ::cin;
using std ::endl;
int main (int argc, char **argv)
{
// const int i; //错误:常量必须初始化
int b = 9;
// const int i = 8; //正确:可以用字面值常量进行初始化
//const int i = b; //正确:常变量可以用普通变量进行初始化
const int *des = 0;
const int *p_int = 0;
des = p_int;
des = &b;
// *des = 9; //错误 const int * 代表指针所指向的空间的值不能进行修改,但指针的指向可以进行改变
int i = 9;
int const &n = i; //正确 常量可以引用普通变量
// n = 10; 错误,n 不可以改变,only read
cout << n <<endl;
// const int u = 8; //错误,试图用普通变量引用常量,就意味着可以通过普通变量进行修改,所以编译不能通过
// int &c = u ;
//cout<< c <<endl;
cout<<"process is runing !"<<endl;
return 0;
}
/*
void my_printf(const char *str);
void my_printf(const char *str)
{
// char *p_string = 0; //不能将常量的值给普通变量,因为p_string可能会修改常量的值
const char * p_string = 0;
p_string = str;
*(p_string +1) = 'P'; //这是错误的,因为const 所指向的对象的值不能改变
cout <<str<<endl;
cout << "runing is successful"<<endl;
return ;
}
int main (int argc,char **argv)
{
char str1[] = "helllo world!";
my_printf(str1);
return 0;
}*/
/*
bool is_short(const string &s1,const string &s2);
bool is_short(const string &s1,const string &s2)
{
if (s1.size() < s2.size()){
cout << "s1 <s2" << endl;
}
int main (int argc, char **argv)
{
string s1;
string s2;
cin >> s1;
cin >> s2;
is_short(s1,s2);
return 0;
}*/
/* C++ 与 C语言的区别
* C语言要求函数名不能重复
* 而C++可以函数名相同,只不过参数列表要不同
void fun(const int i);
void fun(int i);
void fun(const int i)
{
return ;
}
void fun (int i,int j)
{
i += j;
cout << i << endl;
return ;
}
int main (int argc,char ** argv)
{
int i,j;
i = 1;
j = 3;
fun(i , j);
return 0;
}*/
/*
* 一般当当不改变实参的值的的时候,就用const来进行限定
void fun(const int i);
void fun (const int i)
{
int j = 0;
j = i;
cout << j << endl;
return ;
}
int main (int argc,char ** argv)
{
const int des = 9;
int fin = 0;
fin = des;
fun(fin);
return 0;
}
*/
</span>
#include<iostream>
using std ::cout;
using std ::string;
using std ::cin;
using std ::endl;
int main (int argc, char **argv)
{
// const int i; //错误:常量必须初始化
int b = 9;
// const int i = 8; //正确:可以用字面值常量进行初始化
//const int i = b; //正确:常变量可以用普通变量进行初始化
const int *des = 0;
const int *p_int = 0;
des = p_int;
des = &b;
// *des = 9; //错误 const int * 代表指针所指向的空间的值不能进行修改,但指针的指向可以进行改变
int i = 9;
int const &n = i; //正确 常量可以引用普通变量
// n = 10; 错误,n 不可以改变,only read
cout << n <<endl;
// const int u = 8; //错误,试图用普通变量引用常量,就意味着可以通过普通变量进行修改,所以编译不能通过
// int &c = u ;
//cout<< c <<endl;
cout<<"process is runing !"<<endl;
return 0;
}
/*
void my_printf(const char *str);
void my_printf(const char *str)
{
// char *p_string = 0; //不能将常量的值给普通变量,因为p_string可能会修改常量的值
const char * p_string = 0;
p_string = str;
*(p_string +1) = 'P'; //这是错误的,因为const 所指向的对象的值不能改变
cout <<str<<endl;
cout << "runing is successful"<<endl;
return ;
}
int main (int argc,char **argv)
{
char str1[] = "helllo world!";
my_printf(str1);
return 0;
}*/
/*
bool is_short(const string &s1,const string &s2);
bool is_short(const string &s1,const string &s2)
{
if (s1.size() < s2.size()){
cout << "s1 <s2" << endl;
}
int main (int argc, char **argv)
{
string s1;
string s2;
cin >> s1;
cin >> s2;
is_short(s1,s2);
return 0;
}*/
/* C++ 与 C语言的区别
* C语言要求函数名不能重复
* 而C++可以函数名相同,只不过参数列表要不同
void fun(const int i);
void fun(int i);
void fun(const int i)
{
return ;
}
void fun (int i,int j)
{
i += j;
cout << i << endl;
return ;
}
int main (int argc,char ** argv)
{
int i,j;
i = 1;
j = 3;
fun(i , j);
return 0;
}*/
/*
* 一般当当不改变实参的值的的时候,就用const来进行限定
void fun(const int i);
void fun (const int i)
{
int j = 0;
j = i;
cout << j << endl;
return ;
}
int main (int argc,char ** argv)
{
const int des = 9;
int fin = 0;
fin = des;
fun(fin);
return 0;
}
*/