📄 c02.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>C程序的结构</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<script language="javascript">
var prePage="c/c0/c01.htm";
var nextPage="c/c1/c11.htm";
function showwin(url, winname, properties){
window.open(url,winname,properties)
}
</script>
<link rel="stylesheet" href="../cstyle.css" type="text/css">
<bgsound src="../voice/c02.au" loop="1">
</head>
<body background="../img/mainback.jpg" bgproperties="fixed">
<h2 align="center"><a name="_top"></a><font face="楷体_GB2312">引言二 C程序的结构</font></h2>
<div align="center"><center>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="105" align="center"><a href="c02.htm#c021.html#c021">例子 sample.c</a></td>
<td width="122" align="center"><a href="c02.htm#c022.html#c022">sample.c 的解释</a></td>
<td width="123" align="center"><a href="c02.htm#c023.html#c023">C 程序的结构</a></td>
<td width="77" align="center"><a href="c02.htm#c024.html#c024">练习题</a></td>
</tr>
</table>
</center></div>
<hr>
<h3><a name="c021"></a>1. 例子 sample.c</h3>
<blockquote>
<p>请看一个简单的 C 语言例子:</p>
<div align="center"><center><table border="6" width="470" cellspacing="0" cellpadding="6"
height="150" bordercolor="#FF9933">
<tr>
<th width="694" bgcolor="#FF9933">程序</th>
</tr>
<tr>
<td ALIGN="center" width="694" bgcolor="#00FFFF"><p align="left">#include <stdio.h><br>
main() /* 一个简单的程序 */"<br>
{<br>
int num;<br>
num = 1;<br>
printf("我是一台简单的");<br>
printf("计算机。\n");<br>
printf("我喜欢的数字是 %d, 因为它是第一的。\n",num);<br>
}</td>
</tr>
</table>
</center></div><p>让我们看一下 sample.c 的输出:</p>
<p><!-- Aftershock c021.swf 3=250 4=65 17 18 19 40 -->
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="../swflash.cab#version=3,0,0,0" ID="c021" WIDTH="250" HEIGHT="65">
<param name="movie" value="../movie/c021.swf">
<param name="play" value="false">
<param name="loop" value="false">
<param name="quality" value="autohigh">
<param name="menu" value="false">
<param name="bgcolor" value="#E6E6E6"><embed SRC="../movie/c021.swf" swLiveConnect="FALSE" WIDTH="250" HEIGHT="65" PLAY="false"
LOOP="false" QUALITY="autohigh" MENU="false" BGCOLOR="#E6E6E6"
TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</object>
<!-- EndAftershock c021.swf --> </p>
<p align="right"><a href="c02.htm#_top.html#_top">返回页首</a></p>
</blockquote>
<hr>
<h3><a name="c022"></a>2. sample.c 的解释</h3>
<blockquote>
<p><a
href="javascript:showwin('c02_2.htm',null,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,copyhistory=0,width=540,height=350')">请看
sample.c 的解释</a> <img src="../img/lefthand.gif" alt="lefthand.jpg (983 bytes)"
WIDTH="45" HEIGHT="20"></p>
<p align="right"><a href="c02.htm#_top.html#_top">返回页首</a></p>
</blockquote>
<hr>
<h3><a name="c023"></a>3. C程序的结构 </h3>
<blockquote>
<p>现在我们将得到某些一般的 C
语言程序设计规则。一个程序是一个或若干函数的集合。其中的一个必须是
main()。描述一个函数包含函数头和函数体。函数头包括函数名及其参数的说明。<br>
函数体括在一对括号 {} 中, 它包括一系列语句,
每一语句以一分号结束。</p>
<p align="center"> 典型的 C 程序的结构:</p>
<div align="center"><center><table border="0" width="613">
<tr>
<td width="139" align="left">#include</td>
<td width="64" align="center">-----></td>
<td width="398" align="left">预处理语句</td>
</tr>
<tr>
<td width="139" align="left">main()</td>
<td width="64" align="center">-----></td>
<td width="398" align="left">"main" 总是被调用的第一个函数。</td>
</tr>
<tr>
<td width="139" align="left">function_a()</td>
<td width="64" align="center">-----></td>
<td width="398" align="left">函数</td>
</tr>
<tr>
<td width="139" align="left">function_b()</td>
<td width="64" align="center">-----></td>
<td width="398" align="left">函数是 C 程序的构造块。</td>
</tr>
<tr>
<td width="139" align="left">语句</td>
<td width="64" align="center">-----></td>
<td width="398" align="left">函数体是由语句构成的。</td>
</tr>
</table>
</center></div><p> C语言有五种语句:<ol>
<li>说明语句</li>
<li>赋值语句</li>
<li>函数语句</li>
<li>控制流语句</li>
<li>空语句</li>
</ol>
<p align="right"><a href="c02.htm#_top.html#_top">返回页首</a></p>
</blockquote>
<hr>
<h3><a name="c024"></a>4. 练习题</h3>
<blockquote>
<p><a
href="javascript:showwin('c02_41.htm',null,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,copyhistory=0,width=600,height=500')">练习题一</a><img
src="../img/lefthand.gif" alt="lefthand.jpg (983 bytes)" WIDTH="45" HEIGHT="20"></p>
<p><a
href="javascript:showwin('c02_42.htm',null,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,copyhistory=0,width=600,height=500')">练习题二</a><img
src="../img/lefthand.gif" alt="lefthand.jpg (983 bytes)" WIDTH="45" HEIGHT="20"></p>
<p align="right"><a href="c02.htm#_top.html#_top">返回页首</a></p>
</blockquote>
<p align="center"><a href="http://www.nec.sjtu.edu.cn/support/Course/C/c/c1/c11.htm"><img src="../img/next.gif" width="145"
height="30" alt="next.gif (3633 bytes)" border="0"></a></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -