#include iostreamusing namespace std;#ifdef __cplusplusextern C int helloint;;#else#endifint helloint num return num;void showint num cout show int endl;void showconst char ptr 閲嶈浇 cout show char
- 第1行:包含了iostream头文件,该文件包含了输入输出流的定义。
- 第3行:使用了std命名空间,避免在代码中写出std::。
- 第4-8行:通过#ifdef和#ifdef判断是否为C++代码,在C++代码中使用extern "C"声明hello函数为C语言的函数。
- 第10-14行:定义了一个hello函数,接收一个int类型的参数,并返回该参数。
- 第16-20行:定义了一个show函数,接收一个int类型的参数,并输出"show (int)"。
- 第22-26行:定义了一个show函数,接收一个const char*类型的参数,并输出"show (char *)"。
- 第28-32行:定义了main函数,程序的入口函数。
- 第34行:定义了一个指向常量字符的指针ptr,并将其赋值为"hello"。
- 第35行:调用show函数,传入整数10。
- 第37行:调用show函数,传入nullptr,表示空指针。
- 第39行:调用show函数,传入ptr指针。
原文地址: http://www.cveoy.top/t/topic/iJX3 著作权归作者所有。请勿转载和采集!