<h4> </h4> <h4>C++初始化方式</h4> <ul> <ul> <li>与C语言兼容的初始化方式</li> <ul> <li> int n = 20;  int m = 50;</li> <li> int k = n+m –50;</li> <li> int x ; x = n – m ;  这里要注意 在函数和方法中的变量必须要初始化,否者这个变量的值是不定的,函数使用的是栈。</li> </ul> </ul> </ul> <p> </p> <ul> <ul> <li>C++与C语言不同的初始化方式</li> <ul> <li>float p(30.2);  int n(20);  但是这种方式只能在刚定义变量的时候</li> </ul> </ul> </ul> <p> </p> <ul> <ul> <li>C++98的方式 (用户初始化数组和结构体)</li> <ul> <li>int count = {20}; </li> </ul> </ul> </ul> <p> </p> <ul> <ul> <li>C++11的方式</li> <ul> <li>int day{20};</li> </ul> </ul> </ul> <p> </p> <p> </p> <h4>C++常量</h4> <blockquote> <p>常量通常的做法可以使用宏来处理 </p> <pre><pre style="font-size: 12px; font-family: consolas,'Courier New',courier,monospace; margin: 0em; width: 100%; background-color: #ffffff"><span style="color: #0000ff">using</span> <span style="color: #0000ff">namespace</span> std; </pre></pre>
<pre><pre style="font-size: 12px; font-family: consolas,'Courier New',courier,monospace; margin: 0em; width: 100%; background-color: #ffffff">#define ABC 20 </pre></pre>
<pre><pre style="font-size: 12px; font-family: consolas,'Courier New',courier,monospace; margin: 0em; width: 100%; background-color: #ffffff"><span style="color: #0000ff">int</span> _tmain(<span style="color: #0000ff">int</span> argc, _TCHAR* argv[]) </pre></pre>
<pre><pre style="font-size: 12px; font-family: consolas,'Courier New',courier,monospace; margin: 0em; width: 100%; background-color: #ffffff">{ </pre></pre>
<pre><pre style="font-size: 12px; font-family: consolas,'Courier New',courier,monospace; margin: 0em; width: 100%; background-color: #ffffff"></pre></pre>
<pre><pre style="font-size: 12px; font-family: consolas,'Courier New',courier,monospace; margin: 0em; width: 100%; background-color: #ffffff"> cout << ABC << endl; </pre></pre>
<pre><pre style="font-size: 12px; font-family: consolas,'Courier New',courier,monospace; margin: 0em; width: 100%; background-color: #ffffff"><p>}</p><p> </p><h5>宏不是真正意义上的常量 如果要标准一点 要使用const关键字来定义</h5><p> </p><p> </p></pre></pre></blockquote>