详情

首页手游攻略 C语言--不同系统,函数的结果可能不一样

C语言--不同系统,函数的结果可能不一样

佚名 2026-08-07 14:05:54

C语言所有的库函数调用,只能保证语法是一致的,但不能保证执行结果是一致的。

同样的库函数在不同操作系统下执行,结果可能不一样。

system在linux中的执行结果

第一个程序,执行完,返回250#include <stdio.h>#include<stdlib.h>int main(){printf("before sys--------");system("./01_hello");printf("after sys---------");return 250;}------------------------------------------------------------------------------------------------------------------------------------------------在第二个程序中执行第一个程序,并输出第一个程序的返回值#include <stdio.h>#include <stdlib.h>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编译器

1、下载WinGW

2、安装WinGW,WinGW是一个安装器

image

3、运行WinGW,选择安装内容

image

安装

image

4、配置环境变量

image

5、查看是否安装成功

image

windows 环境编译并运行c程序

第一个程序#include <stdio.h>#include<stdlib.h>int main(){ printf("system---------");return 250;}
第二个程序,执行第一个程序,并打印第一个程序返回的值#include <stdio.h>#include <stdlib.h>int main(){int a=system("system.exe");//打印变量a的值printf("a=%d",a);}

编译和运行结果

image

编译产生的结果

image

点击查看更多
推荐专题
热门阅读