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;
}
相关推荐
胖大和尚10 分钟前
在C++的类中,是否可以把函数声明成__device__
c++·cuda
脚踏实地皮皮晨13 分钟前
003003001_Grid控件
开发语言·windows·算法·c#·visual studio
十年磨剑走天涯17 分钟前
C++ STL 容器操作复杂度速查表
开发语言·c++
always_TT24 分钟前
【Python requirements.txt 依赖管理】
开发语言·python
ziguo112226 分钟前
Windows API MessageBox 函数详解
c语言·c++·windows·visualstudio
王老师青少年编程30 分钟前
2023年CSP-J初赛真题及答案解析(11-15)
c++·真题·csp-j·答案·csp·初赛·信奥赛
15Moonlight33 分钟前
C++进阶(09):特殊类设计
开发语言·c++
宁风NF38 分钟前
JavaScript:网络请求与前端通信
开发语言·前端·javascript·网络·学习·ecmascript
Logintern091 小时前
py文件开头为什么需要加:from __future__ import annotations
开发语言·python
caishenzhibiao1 小时前
降雨带波段点差 同花顺期货通指标
java·c语言·c#