【C++】缺省函数

可缺省 可缺省 可缺省 的参数(如:代码中的 p S t r 指针 pStr指针 pStr指针) 在 函数定义 函数定义 函数定义 时对 形参 形参 形参赋予指定的初始值( p S t r = N U L L pStr=NULL pStr=NULL)当 缺省 缺省 缺省 第二个参数时,函数就认定 p S t r = N U L L pStr=NULL pStr=NULL

c 复制代码
#include <bits/stdc++.h>
using namespace std;
#include <sal.h>

void Print(_In_opt_ int* pInt, _In_opt_ string* pStr=NULL) {	//函数可缺省
	if (pInt != NULL)
		cout << *pInt;
	if (pStr != NULL)
		cout << *pStr;
}


int main(int* argc, char* argv[]) {
	int a = 1;
	string s1 = "jUicE";
	Print(&a);
	Print(NULL,&s1);
	return 0;
}
相关推荐
·present·4 分钟前
CSAPP(lecture 3)
c++
别动我齐刘海29 分钟前
机器人 C++ / 系统联调补强2——异常处理、Protobuf
linux·c++·人工智能·学习·算法·机器学习·机器人
basketball61640 分钟前
C++ 中字符串与常见类型的转换总结
开发语言·c++
等我调个Bug1 小时前
C++智能指针通俗讲解
开发语言·c++
kyle~3 小时前
时间同步 --- PTP 与 Scheduled Action Command
c++·数码相机·机器人·传感器
syagain_zsx5 小时前
WebSocket 教程:websocketpp 写 echo 服务端
linux·网络·c++·websocket·网络协议·工具库
大陈子编程5 小时前
C++ CSP-J 与 CSP-S 题单:洛谷 140 题知识点全覆盖
c++
张小姐的猫6 小时前
【MySQL】数据类型
android·linux·数据库·c++·mysql·adb·php
讳疾忌医丶6 小时前
编译器眼中的 C++ 循环:从指针别名、IEEE 754 结合律到 SIMD 语义证明
开发语言·c++