C語言基礎 1 4 C語言陣列

2021-07-25 14:38:15 字數 2679 閱讀 1612

字元陣列與字串

字元陣列的輸入和輸出

字串拷貝

字串比較

字串連線

_getch()函式包含在conio.h的標頭檔案中。

避免資料溢位

3-1

#include 

int main()

3-2

#include 

#include

int main

() //else

///*if (a%2==0)

else

*//*if (a % 4 == 0)

else

else}}

else

*//*if (a==1)

else

if (a==2)

else

if (a==3)

else

if (a == 4)

else

if (a == 5)

else

if (a == 6)

else

if (a == 7)

*/ switch (a)

system("pause");

return

0;}

3-3

// day3-03.cpp : 定義控制台應用程式的入口點。

//#include "stdafx.h"

#include

#include

#include

int _tmain(int argc, _tchar* argv)

3-4

// day3-04.cpp : 定義控制台應用程式的入口點。

//#include "stdafx.h"

#include

#include

int _tmain(int argc, _tchar* argv)

3-5

// day3-05.cpp : 定義控制台應用程式的入口點。

//#include "stdafx.h"

#include //注意_getch()的標頭檔案是這個

int _tmain(int argc, _tchar* argv)

3-6

// day3-06.cpp : 定義控制台應用程式的入口點。

//#include "stdafx.h"

#include

int _tmain(int argc, _tchar* argv)

3-7

// day3-07.cpp : 定義控制台應用程式的入口點。

//字串比較

#include "stdafx.h"

#include

int _tmain(int argc, _tchar* argv)

3-8

// day3-08.cpp : 定義控制台應用程式的入口點。

//字串連線

#include "stdafx.h"

#include

#include

int _tmain(int argc, _tchar* argv)

; char str2 = ;

strcat_s(str1, 30,str2);

printf("%s\n", str1);

system("pause");

return

0; }

3-9

// day3-09.cpp : 定義控制台應用程式的入口點。

//再談輸入輸出

#include "stdafx.h"

#include

int _tmain(int argc, _tchar* argv)

3-10

// day3-11.cpp : 定義控制台應用程式的入口點。

//使用if與goto構造迴圈結構

#include "stdafx.h"

int _tmain(int argc, _tchar* argv)

printf("%d\n", sum);

return

0;}

3-11

: 定義控制台應用程式的入口點。

//switch-case 實現會移動的座標

#include "stdafx.h"

#include

int _tmain(int argc, _tchar* argv)

case

's':

case

's':

case

'a':

case

'a':

case

'd':

case

'd':

default:

break;

}goto sign;

return

0; return

0;}

1 4 C 語言基礎 陣列

type arrayname 宣告乙個int陣列 int arry 宣告的時候指定陣列的長度為5 這個時候的初始化值為0 int arry2 new int 5 宣告的時候初始化值 初始化的值個數必須和指定的長度匹配 int array3 new int 5 字串陣列 string arrstr 陣...

14 C語言 陣列

c 語言支援陣列資料結構,它可以儲存乙個固定大小的相同型別元素的順序集合。陣列是用來儲存一系列資料,但它往往被認為是一系列相同型別的變數。陣列的宣告並不是宣告乙個個單獨的變數,比如 number0 number1 number99,而是宣告乙個陣列變數,比如 numbers,然後使用 numbers...

14 C 基礎 陣列

陣列宣告形如 a d 其中大小必須大於 0 const unsigned sz 10 常量表示式 int arr sz 含有 10 個整數的陣列 int parr 10 含有 10 個整數的陣列初始化 陣列 int main cout value a 0 endl value 0 return 0 ...