C and C++ code

##%zu for sizeof

##return/exit

在main函数中调用exit和return结果是一样的,但在子函数中调用return只是代表子函数终止了,在子函数中调用exit,那么程序终止。

##NULL
#define NULL ((void *)0)

const&pointer

c 复制代码
	int a = 1;
	int b = 2;

//指向常量的指针
	//修饰*,指针指向内存区域不能修改,指针指向可以变
	const int * p1 = &a; //等价于int const *p1 = &a;
	//*p1 = 111; //err
	p1 = &b; //ok

//指针常量
	//修饰p1,指针指向不能变,指针指向的内存可以修改
	int * const p2 = &a;
	//p2 = &b; //err
	*p2 = 222; //ok

read from right to left:
const int * p: a pointer p point to const int
p-->a pointer p
*-->point to

int * const p: a const pointer p point to int

pointer - pointer

c 复制代码
#include <stdio.h>

int main()
{

    int a[] = {0,1,2,3,4};
    int * p2 = &a[2];
    int * p4 = &a[4];

    int n = p4 - p2;//2
  
    int m = (int)p4 - (int)p2;//8

    
    return 0;
}
相关推荐
星落梦生5 小时前
SpringAOP基础笔记(7)
java·开发语言
我不会插花弄玉6 小时前
13.多路转接epoll【由浅入深-网络】
网络·c++·epoll
曹牧7 小时前
Java:“刷新雪崩”
java·开发语言
郝学胜-神的一滴8 小时前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl
西西弗Sisyphus8 小时前
C++ explicit 关键字工程实践
开发语言·c++
戊本菌9 小时前
进程(三)进程优先级:谁先上 CPU
linux·c语言·硬件架构
郝学胜-神的一滴10 小时前
Effective Python 条款35:用类封装替代生成器异常注入
开发语言·人工智能·python·金融·pandas·scikit-learn·matplotlib
feixing_fx10 小时前
原始类型与引用类型:赋值时到底复制了什么
开发语言·前端·javascript·前端框架
wuyk55510 小时前
Python办公自动化-第02讲-Excel文件认知与四大库选型
开发语言·python·excel
AIgorithmGEEK11 小时前
std::unordered_map 与 std::unordered_set:接口、算法技巧与权衡 (速查)
c++·算法·哈希表·负载因子·桶·unordered_map·unordered_set