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;
}
相关推荐
fqbqrr6 小时前
2606C++,C++构的多态
开发语言·c++
biter down7 小时前
从 0 到 1 搭建 Python 接口自动化测试框架(博客系统实战)
开发语言·python
小欣加油7 小时前
leetcode56 合并区间
c++·算法·leetcode·职场和发展
Yolo_TvT7 小时前
C++:析构函数
c++
threelab8 小时前
Three.js 物理模拟着色器 | 三维可视化 / AI 提示词
开发语言·前端·javascript·人工智能·3d·着色器
武器大师728 小时前
lv_binding_js 代码解读
开发语言·javascript·ecmascript
不知名的老吴8 小时前
线程的生命周期之线程“插队“
java·开发语言·python
Hello:CodeWorld9 小时前
C 风格变参 vs C++ 变参模板:核心区别与选型指南
c语言·c++·算法
kaikaile19959 小时前
数字全息图处理系统(C# 实现)
开发语言·c#