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;
}
相关推荐
C^h7 小时前
c++ string
开发语言·c++
听风说ml7 小时前
socket编程 【C语言】
c语言·udp·tcp·socket编程
raindayinrain7 小时前
c++高性能--原子操作,无锁编程,操作顺序
开发语言·c++·性能优化
学逆向的7 小时前
C++ 合并命名空间
开发语言·c++·网络安全
Zhao-Jichao7 小时前
VS2026 打包 C++ 程序生成 EXE,借助 Installer Project 扩展工具
开发语言·c++
学逆向的8 小时前
C 局部静态变量
c语言·开发语言·网络安全
小徐不徐说8 小时前
C++ 接口与插件设计:从工厂注册到 Qt 动态插件
数据库·c++·qt·系统架构·程序设计
大都督会赢的9 小时前
C++第一节课
开发语言·c++
UIU1149 小时前
P1233 [ICPC 2001 Taejon R] 木棍加工
数据结构·c++·算法·动态规划
“AI国潮设计-小江”9 小时前
【AIGC实战】Python+Stable Diffusion打造“英歌舞财神”IP,解锁“马到成功”等爆款情绪营销文案设计
开发语言·人工智能·python·prompt·aigc