-
a = 10,就是將 10 賦給 a 這個變量;
a = b? 將b的值賦給a
查看全部 -
利用程序輸出數據類型長度
#include <stdio.h>
int main(int argc,char **argv)
{
? ?printf("int: %d\n", sizeof(int));
? ?
? ?return 0;
}查看全部 -
bit中文名“位”
2 個 bit 組合起來,可以得到 2 的 2 次方,也就是 4 個數字的數據容量。
?8 個 bit 組合起來,可以得到 2 的 8 次方,也就是 256 個數字的數據容量。
在計算機中,我們把 8 個 bit 的容量稱之為 1 個 byte, 中文叫做字節。8bit = 1 byte
查看全部 -
cin
#include <stdio.h>
#include <iostream>
int main(int argc,char **argv)
{
? ?int a = 0;
? ?int b = 0;
? ?std::cin >> a >> b;
? ?return 0;
}使用 cin 可以連續從鍵盤讀取想要的數據,以空格、tab鍵或換行符作為分隔符。cin 相對于 scanf 來說,不需要指明類型,用起來更方便一些。
查看全部 -
cout
#include <stdio.h>
#include <iostream>
int main(int argc,char **argv)
{
? ?int a = 99;
? ?int b = 98;
? ?std::cout << "a: " << a << ", b: " << b << std::endl;
? ?return 0;
}輸出結果?a:?98,?b:?99 cout?相對?printf?來說,更易用一些,只需要將想要輸出的內容用?<<?連接起來就好了。
查看全部 -
/*C
#include<stdio.h>
int main(int argc,char **argv)
{
? ? int a=1; int b=2; int c=a+b;? int d=a-b; int e=a*b; int f=a/b;? int g=a%b;
? ? printf("%d %d %d %d %d",c,d,e,f,g);
? ? return 0;
}
//語言輸入Hello World!This is C Style
#include <stdio.h>
int main()
{
? ? printf("Hello World!This is C Style");
? ? return 0;
? ??
}
*/
//C++輸出
#include <iostream>
using namespace std;
int main()
{
? ? cout << "Hello world!This is C++ Style" <<endl;
? ? return 0;
}
查看全部 -
我們在上一小節的 Hello World 中,寫了這樣一段程序
#include <stdio.h> int main(int argc,char **argv) { ? ?printf("Hello World!\n"); ? ?return 0; }
在這段程序中,我們提到一個 main 函數。這個 main 函數是程序的入口,一個程序里,有且只有一個 main 函數。程序從 main 函數開始執行,到 main 函數結束而終止。
我們來看看這個函數里其他的部分。
首先是 (int argc,char **argv) ,這是一個參數列表。我們可以看到,這里有兩個參數,第一個參數argc表示參數個數,第二個參數argv是參數組,兩個參數一起表達了這個程序的啟動參數。
另外一個是return語句,我們可以看到 main 函數有一個返回值,這個返回表示程序的執行結果。我們這個 Hello Wolrd 程序里面,返回的是 0。0 表示程序執行成功,沒有出現問題。如果這里返回的是非 0 ,那么表示程序執行出現問題。
查看全部 -
?在程序中打印Hello World!,其實就是一個標準的輸出行為,因為程序向外界傳輸了信息,這個信息就是Hello World!。
main()函數,沒錯,就是字面上看到的意思,主函數,這是一個特殊的函數,它是程序的入口函數。一個程序里,有且只有一個 main 函數。
向世界問好核心語句
printf("Hello World!\n");
這句代碼的意思是向標準輸入輸出流中輸出一行 Hello World!,\n表示換行符。printf 這個功能在 stdio.h 中包含,這也就是為什么我們要在程序一開頭就 include 它的原因。C++ Style
看到這里,有的學過 C 語言的同學會說,這段程序怎么和 C 語言的 Hello World 一摸一樣啊。事實上,這段程序本身就是一段 C Style 的程序。C++ 是兼容 C 語言的大部分特性的,C 語言的 stdio 和 printf 在 C++ 程序中是一點問題都沒有的。事實上,這也是很多成熟 C++ 項目的使用方式。那么 C++ 有什么專有的輸出方式呢?其實是有的。我們再來看一個程序。
#include <iostream> int main(int argc,char **argv) { ? ?std::cout << "Hello World!\n" << std::endl; ? ?return 0; }
在這個程序里面,我們沒有包含 stdio,而是包含了 iostream,這是 C++ 里的 io 流的頭文件。
main 函數中,輸出語句變成了std::cout << "Hello World!\n" << std::endl;
這就是 C++ 風格的 Hello World 。在實際開發中,這兩種輸出語句都可以使用。
查看全部 -
#include <stdio.h>
main()
{
? ? int a,b ,temp;
? ? a=1;
? ? b=2;
? ? temp=a;//temp=1
? ? a=b;//a=2
? ? b=temp;//b=1
? ? printf("%d,%d",a,b);//a=2,b=1
}
查看全部 -
#include <stdio.h>
main()
{
printf("char:%d\n",sizeof(char));
printf("int:%d\n",sizeof(int));
printf("float:%d\n",sizeof(float));
printf("double:%d\n",sizeof(double));
printf("long:%d\n",sizeof(long));
printf("short:%d\n",sizeof(short));
}
查看全部 -
- 程序從 main 函數開始執行,到 main 函數結束而終止。
查看全部 -
iostream
std::cout<<"\n"<<std::endl
查看全部 -
switch—case語句后面的case都不滿足,也想執行一些相應的命令,就用default語句
查看全部 -
switch-case case語句后只能跟常量,來判別與switch語句后的常量是否相等。
一旦匹配到相應的case語句,switch會把后面的case語句都執行一遍。
查看全部 -
inline函數-內聯函數. 必須在函數定義時使用,不能放在函數聲明的時候使用。如inline int a( int ){ … ;}
內聯函數相當于把在主函數外定義的函數復制到主函數里,少了值的傳遞。但也帶來復制的壓力
查看全部
舉報