平常心的一些认识

对于我们在学习的过程中难免会遇到一些问题如何去学习问题背后的知识,才是我们应该考虑的

const 是一个C语言(ANSI C)的关键字,它限定一个变量不允许被改变,产生静态作用(const is a key word of C language(ANSC C),which defines a variable that does not to be chagned,producing a static effect)
话不多说,请看:
int i=5;
const int*p=&i;
int const*p=&i;
int *const p=&i;
如果你已经明白以上三句代码所表达的意思了,那么你就不用继续往下看了,如果你没有完全明白,不着急,请继续
往下看(If you have understood the meaning of the above three codes,then you don't need to looking down.Instead,don't worry please and look down)
const的转换,以排序来做介绍
*/

/*
const int*p=&i;  所指是const
i=6; 修改i √
*p=6; 修改p所指的 ×
如果此时增加一个j
p=&j; 修改j √
int const*p=&i;同上
*/

/*
int *const p=&i;
是指p不能被修改
如果此时增加一个j
p=&j; 修改j ×
*/
/*
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int cmps(const void*a,const void*b)//升序
{
return *(int*)a-*(int*)b;
}
int cmpd(const void*a,const void*b)//降序
{
return (*(int*)a-*(int*)b)*-1;
}
int main()
{
int a[5]={1,3,2,4,5};
qsort(a,5,sizeof(a[0]),cmps);
cout<<"升序为:"<<endl;
for(int i=0;i<5;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
qsort(a,5,sizeof(a[0]),cmpd);
cout<<"降序为:"<<endl;
for(int i=0;i<5;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
return 0;
}
//此时的int cmps(const void*a,const void*b),是指传进来的a,b,在此函数内部不会改变


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值