📄 const.cpp
字号:
// const.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
const int value = 1100;
const height =1000;
const char title[]="computer science" ;
const char* p=title;
using namespace std;
void f(const char* p)
{
//p[0]='c';
printf("%s\n",p);
}
void g(const string& str)
{
cout<<str<<endl;
}
int main(int argc, char* argv[])
{
char s[]="bate" ;
char m[]="make" ;
const char* p=s;
p=m;
cout<<p<<endl;
// p[0]='m' ;
#if 1
char * const p1=s;
// p1=m;
p1[0]='m';
cout<<p1<<endl;
#endif
// 不能将常量的地址赋值给一个非常量的指针
// char* p2= title;
// int *p3=&value;
g("Hello everyone"); //如果去掉参数声明中的const,能否编译过去?
f("Hello everyone");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -