#include <iostream>
using namespace std;
int main(void)
{
int x = 3;
//定义引用,y是x的引用
int &y = x;
//打印x和y的值
cout << x << endl;
cout << y << endl;
//修改y的值
y = 5 ;
//再次打印x和y的值
cout << x << "," << y <<endl;
return 0;
}
using namespace std;
int main(void)
{
int x = 3;
//定义引用,y是x的引用
int &y = x;
//打印x和y的值
cout << x << endl;
cout << y << endl;
//修改y的值
y = 5 ;
//再次打印x和y的值
cout << x << "," << y <<endl;
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
int x = 3;
//定义引用,y是x的引用
int &y = x;
//打印x和y的值
cout<< x <<","<< y <<endl;
//修改y的值
y = 50;
//再次打印x和y的值
cout<< x << ","<< y <<endl;
return 0;
}
using namespace std;
int main(void)
{
int x = 3;
//定义引用,y是x的引用
int &y = x;
//打印x和y的值
cout<< x <<","<< y <<endl;
//修改y的值
y = 50;
//再次打印x和y的值
cout<< x << ","<< y <<endl;
return 0;
}
已采纳回答 / qq_言懿_03305352
int *p = NULL; 定义一个指针变量p,其指向的内存里面保存的是int 类型的数据;在定义变量p 的同时把p 的值设置为0×00000000,而不是把*p 的值设置为0×00000000。这个过程叫做初始化,是在编译的时候进行的。 int *p; *p = NULL; 第一行代码,定义了一个指针变量p,其指向的内存里面保存的是int 类型的数据;但是这时候变量p 本身的值是多少不得而知,也就是说现在变量p 保存的有可能是一个非法的地址。第二行代码,给*p 赋值为NULL,即给p指向的内存赋值为N...
2016-05-16
语法:
基本数据类型引用:&a2 = a1;
结构体类型引用:Student &b2 = b1;
指针类型引用:*&p2 = p2;
基本数据类型引用:&a2 = a1;
结构体类型引用:Student &b2 = b1;
指针类型引用:*&p2 = p2;
2016-05-13
include <string.h>
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申请100个char类型的内存
char *str = new char[100];
//拷贝Hello C++字符串到分配的堆中的内存中
strcpy(str, "Hello imooc");
//打印字符串
cout<<str<<endl;
//释放内存
delete []str;
str=NULL;
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申请100个char类型的内存
char *str = new char[100];
//拷贝Hello C++字符串到分配的堆中的内存中
strcpy(str, "Hello imooc");
//打印字符串
cout<<str<<endl;
//释放内存
delete []str;
str=NULL;
return 0;
}
已采纳回答 / 慕沐8501324
#include <string.h>#include <iostream>#include <stdlib.h>using namespace std;#pragma warning(disable:4996)int main(void){ //在堆中申请100个char类型的内存 char *str = new char[100]; //拷贝Hello C++字符串到分配的堆中的内存中 strcpy(str, "Hello imooc"); //打印字符串 cout...
2016-05-09