C语言所有的库函数调用,只能保证语法是一致的,但不能保证执行结果是一致的。
同样的库函数在不同操作系统下执行,结果可能不一样。
system在linux中的执行结果第一个程序,执行完,返回250#include #includeint main(){ printf("before sys--------
"); system("./01_hello"); printf("after sys---------
"); return 250;}------------------------------------------------------------------------------------------------------------------------------------------------在第二个程序中执行第一个程序,并输出第一个程序的返回值#include #include int main(){ int a=system("./02_system"); //打印变量a的值 printf("a=%d
",a);}------------------------------------------------------------------------------------------------------------------------------------------------结果[root@localhost day03]# ./03_return before sys--------hello cafter sys---------//输出的是4864,不是250a=4864
------------------------------------------------------------------------------
system在windows中的执行结果
windows 下安装gcc编译器
2、安装WinGW,WinGW是一个安装器
3、运行WinGW,选择安装内容
安装
4、配置环境变量
5、查看是否安装成功
windows 环境编译并运行c程序第一个程序#include #includeint main(){ printf("system---------
"); return 250;}第二个程序,执行第一个程序,并打印第一个程序返回的值#include #include int main(){ int a=system("system.exe"); //打印变量a的值 printf("a=%d
",a);}
编译和运行结果
编译产生的结果