博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何引用另外一个文件中的串, 顺便说说void print();和(void)print();的区别
阅读量:4139 次
发布时间:2019-05-25

本文共 748 字,大约阅读时间需要 2 分钟。

     由于需要, 所以小写一下。

     main.cpp中的代码为:

#include 
using namespace std;extern char str[];int main(){ cout << str << endl; return 0;}
     test.cpp中的代码为:

char str[100] = "abcdefg";
     程序的结果为:abcdefg

     下一道菜:

     main.cpp

#include 
using namespace std;void print();extern char str[];int main(){ cout << str << endl; // cout << sizeof(str) << endl; //编译错误 cout << strlen(str) << endl; // 7 strcpy(str, "xyz"); cout << str << endl; print(); // 输出hello world, xyz, 可见, 上面的strcpy改变了test.cpp中的值 return 0;}

    test.cpp

#include 
char str[100] = "abcdefg";void print(){ printf("hello world, %s\n", str);}

      输出结果:

abcdefg

7
xyz
hello world, xyz

     

       最后看一下void print();和(void)print();的区别:

       void print();是生命, 而(void)print();是调用, 在代码中非常常见, 为什么要加(void)呢, 多数为了通过静态检查工具的检查。

     

转载地址:http://ylrvi.baihongyu.com/

你可能感兴趣的文章
九度:题目1008:最短路径问题
查看>>
九度Online Judge
查看>>
九度:题目1027:欧拉回路
查看>>
九度:题目1012:畅通工程
查看>>
九度:题目1017:还是畅通工程
查看>>
九度:题目1034:寻找大富翁
查看>>
第六章 背包问题——01背包
查看>>
第七章 背包问题——完全背包
查看>>
51nod 分类
查看>>
1136 . 欧拉函数
查看>>
面试题:强制类型转换
查看>>
Decorator模式
查看>>
Template模式
查看>>
Observer模式
查看>>
高性能服务器设计
查看>>
性能扩展问题要趁早
查看>>
MySQL-数据库、数据表结构操作(SQL)
查看>>
OpenLDAP for Windows 安装手册(2.4.26版)
查看>>
图文介绍openLDAP在windows上的安装配置
查看>>
Pentaho BI开源报表系统
查看>>