⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c52.htm

📁 经典c语言教程
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>结构的初始化 </title>
<script language="javascript">
   var prePage="c/c5/c51.htm";
   var nextPage="c/c5/c53.htm";
</script>

<link rel="stylesheet" href="../cstyle.css" type="text/css">
</head>

<body background="../img/mainback.jpg" bgproperties="fixed">

<h2 align="center"><font face="楷体_GB2312">5.2 <font COLOR="#000000">结构的初始化</font></font></h2>

<hr>

<blockquote>
  <p align="left">只有外部的或静态的结构变量可以被初始化,结构变量的值列在 
  { } 中间, 并用 ',' 分隔。</p>
  <p align="left">例如:</p>
  <table border="0" width="63%">
    <tr>
      <td width="45%">static struct date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
      {<br>
      &nbsp;&nbsp;&nbsp; int month;<br>
      &nbsp;&nbsp;&nbsp; int day;<br>
      &nbsp;&nbsp;&nbsp; int year;<br>
      }today={9,22,1990};</td>
      <td width="55%"><img src="../img/c521.gif" alt="c521.jpg (4179 bytes)" WIDTH="143"
      HEIGHT="133"></td>
    </tr>
  </table>
  <p align="left">解释:<br>
  结构 date 包括三个成员:month, day和 year。此语句说明了一个变量 today, 
  类型为 struct date, 初值为 9 22 1990。</p>
  <table border="0" width="63%">
    <tr>
      <td width="44%">static struct book 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
      {<br>
      &nbsp;&nbsp;&nbsp; char title[30];<br>
      &nbsp;&nbsp;&nbsp; char author[20];<br>
      &nbsp;&nbsp;&nbsp; float price;<br>
      }libry={<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;To Build a Fire&quot;,<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;Jack London&quot;,<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.95<br>
      &nbsp;&nbsp;&nbsp; };</td>
      <td width="56%"><img src="../img/c522.gif" alt="c522.jpg (5713 bytes)" WIDTH="185"
      HEIGHT="133"></td>
    </tr>
  </table>
  <p align="left"> </p>
  <p align="left">解释:<br>
  title 和 author 是 libry 的成员, 
  它们都是字符数组。为了使成员之间的关系比较明显, 
  我们用一行来初始化每个成员, 
  但是所有的编译器都要求用逗号分隔开各个成员的初始值。</p>
</blockquote>

<p align="center"><a href="http://www.nec.sjtu.edu.cn/support/Course/C/c/c5/c53.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 + -