#include <IOSTREAM>
#include <STDIO.H>
using namespace std;
//这是引用变量的使用!
void YinYong()
{
int ivar = 10;
int &rvar = ivar;
rvar = 20;
printf("ivar = %d",ivar);
printf("\nrvar = %d \n",rvar);
}
//异或运算交换数值,无中间变量!
void Changefun()
{
int ivar = 5;
int rvar = 4;
cout<<"交换前:\nivar = "<<ivar<<"\nrvar = "<<rvar<<"\n";
ivar = ivar ^ rvar;
rvar = rvar ^ ivar;
ivar = ivar ^ rvar;
cout<<"交换后:\nivar = "<<ivar<<"\nrvar = "<<rvar<<"\n";
}
//sizeof函数测试
void Sizefun()
{
int ivar = 10;
int size = sizeof(ivar);
cout<<"size is:"<<size<<"\n";
int iarray[]={1,6,7,8,13,14,145,5,6,7,8,89};
size = sizeof(iarray);
cout<<"size is:"<<size<<"\n";
char ibrrby[] = "hello";
size = sizeof(ibrrby);
cout<<"size is:"<<size<<"\n";
}
//指针指向数组,无论数组多大sizeof都是4;面试考核专用!
void poinfun()
{
int iarray[]={1,5,6,7,8,9,0,3};
int *parray = iarray;
int size = sizeof(parray);
cout<<"size is:"<<size<<"\n";
}
void poindele()
{
int *pvar = new int;
*pvar =10;
delete pvar;
//注意!!!:new 一个数组,然后删除的方法!
int *ipvar = new int[5];
delete [] ipvar;
}
//逗号表达式在for循环中的应用!
void forfun()
{
int i = 0;
int j = 0;
int sum = 0;
for(i=0,j=10;i<j;i++)
{
sum+= i + j;
printf("%d\n",sum);
}
}
//goto语句的使用;
void gotofun()
{
int ivar = 0;
int num = 0;
if(ivar < 10)
{
goto laber;
}
printf("num = %d\n",num);
laber:
ivar++;
num+=num+ivar;
}
int main()
{
//YinYong();
//Changefun();
//Sizefun();
//poinfun();
// poindele();
//forfun();
gotofun();
return 0;
}
C++基础学习系列--0(前言)、异或运算和sizeof函数
最新推荐文章于 2024-05-14 22:56:12 发布