第一范文网 - 专业文章范例文档资料分享平台

C语言基础教程

来源:用户分享 时间:2025/6/1 12:25:51 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

包括初始化)跟在一个复合语句的左花括号的后面, 直到配对的右花括号为止。它 的作用域仅在这对花括号内, 当程序执行到出花括号时, 它将不复存在。当然, 内 层中的变量即使与外层中的变量名字相同, 它们之间也是没有关系的。 例9.

#include int i=10; int main() {

int i=1;

printf(\ {

int i=2;

pritnf(\ {

extern i; i+=1;

printf(\ }

printf(\ }

printf(\ return 0; }

运行结果为

1 2 11 3 2

从程序运行的结果不难看出程序中各变量之间的关系, 以及各个变量的作用域。

C语言基础教程(三十二)

网上收集整理 函数篇(a)

函数名: abort

功 能: 异常终止一个进程 用 法: void abort(void); 程序例:

#include #include

int main(void) {

printf(\ abort();

return 0; /* This is never reached */ }

函数名: abs

功 能: 求整数的绝对值 用 法: int abs(int i); 程序例:

#include #include

int main(void) {

int number = -1234;

printf(\ return 0; }

函数名: absread, abswirte

功 能: 绝对磁盘扇区读、写数据

用 法: int absread(int drive, int nsects, int sectno, void *buffer); int abswrite(int drive, int nsects, in tsectno, void *buffer); 程序例:

/* absread example */

#include #include #include #include

int main(void) {

int i, strt, ch_out, sector; char buf[512];

printf(\ getch(); sector = 0;

if (absread(0, 1, sector, &buf) != 0) {

perror(\ exit(1); }

printf(\

strt = 3;

for (i=0; i<80; i++) {

ch_out = buf[strt+i]; putchar(ch_out); }

printf(\ return(0); }

函数名: access

功 能: 确定文件的访问权限

用 法: int access(const char *filename, int amode); 程序例:

#include #include

int file_exists(char *filename);

int main(void) {

printf(\

file_exists(\ return 0; }

int file_exists(char *filename) {

return (access(filename, 0) == 0); }

函数名: acos

功 能: 反余弦函数

用 法: double acos(double x); 程序例:

#include #include

int main(void) {

double result; double x = 0.5;

result = acos(x);

printf(\ return 0; }

函数名: allocmem

功 能: 分配DOS存储段

用 法: int allocmem(unsigned size, unsigned *seg); 程序例:

#include #include #include

int main(void) {

unsigned int size, segp; int stat;

size = 64; /* (64 x 16) = 1024 bytes */ stat = allocmem(size, &segp); if (stat == -1)

printf(\ else

printf(\ stat);

return 0; }

函数名: arc

功 能: 画一弧线

用 法: void far arc(int x, int y, int stangle, int endangle, int radius); 程序例:

#include #include #include #include

int main(void) {

/* request auto detection */

int gdriver = DETECT, gmode, errorcode; int midx, midy;

int stangle = 45, endangle = 135; int radius = 100;

/* initialize graphics and local variables */ initgraph(&gdriver, &gmode, \

/* read result of initialization */

errorcode = graphresult(); /* an error occurred */ if (errorcode != grOk) {

printf(\ printf(\ getch();

exit(1); /* terminate with an error code */ }

midx = getmaxx() / 2; midy = getmaxy() / 2; setcolor(getmaxcolor());

/* draw arc */

arc(midx, midy, stangle, endangle, radius);

/* clean up */ getch();

closegraph(); return 0; }

函数名: asctime

功 能: 转换日期和时间为ASCII码

用 法: char *asctime(const struct tm *tblock); 程序例:

#include #include #include

int main(void) {

struct tm t; char str[80];

/* sample loading of tm structure */

t.tm_sec = 1; /* Seconds */

搜索更多关于: C语言基础教程 的文档
C语言基础教程.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c8a1ou1x73m28mwx144wv_9.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top