freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內容

chap08_指針-閱讀頁

2024-08-20 17:25本頁面
  

【正文】 ) { int i, j, n, t, a[10]。 for(i = 0。 i++) scanf(%d, amp。 for(i = 1。 i++) for(j = 0。 j++) if(a[j] a[j+1]) { t = a[j]。 a[j+1] = t。 } int main(void ) { int i, a[10]。 i10。a[i])。 for(i=0。 i++) printf(%d , a[i])。 return 0。 for(i=1。 i++) for(j=0。 j++) if(array[j]array[j+1]){ t = array[j]。 array[j+1] = t。 int main (void) { char line [MAXLINE]。 gets(line)。 printf (“After being encrypted: %s\n, line)。 } void encrypt ( char *s) { for ( 。\039。z39。a39。 } Input the string: hello hangzhou After being encrypted: ifmmp!ibohaipv 字符串和字符指針 ? 字符串常量 array point ?用一對雙引號括起來的字符序列 ?被看做一個特殊的一維字符數(shù)組 ,在內存中連續(xù)存放 ?實質上是一個指向該字符串首字符的指針常量 char sa[ ] = array。 char sa[ ] = array。 printf(%s , sa)。 printf(%s\n, string)。 printf(%s , sp+3)。 ray nt tring 數(shù)組名 sa、指針 sp和字符串 string 的值都是地址 字符數(shù)組與字符指針的重要區(qū)別 char sa[ ] = This is a string。 sa T h i s i s a s t r i n g \0 sp T h i s i s a s t r i n g \0 如果要改變數(shù)組 sa所代表的字符串,只能改變數(shù)組元素的內容 如果要改變指針 sp所代表的字符串,通常直接改變指針的值,讓它指向新的字符串 示例 char sa[ ] = This is a string。 strcpy (sa, Hello)。 sa = “Hello”。 char *s 。 char *s, str[20]。 scanf(“%s”, s)。 for(i = 0。\039。z39。a39。 } void encrypt ( char *s) { for ( 。\039。z39。a39。 } 常用的字符串處理函數(shù) ? 函數(shù)原型在 或 中給出 字符串的輸入和輸出 ?輸入字符串: scanf( )或 gets( ) ?輸出字符串: printf( )或 puts( ) ? char str[80]。 while((str[i] = getchar( )) != 39。) i++。\039。\n39。 39。\t39。 for(i = 0。 i++) putchar(str[i])。 (4) puts(str) puts(hello)。\039。 scanf(%s, str)。 printf(%s, Hello)。 } 例 815 字符串輸入輸出函數(shù)示例 include int main( ) { char str[80]。 puts(str)。 return 0。 將字符串 str2 復制到 str1 中 static char str1[20]。 字符串復制函數(shù) strcpy() h a p p y \0 \0 strcpy(str1, str2)。 str1中 : w o r l d \0 include “” include “” int main(void ) { char str1[20], str2[20]。 strcpy(str1,str2)。 return 0。 連接兩個字符串 str1和 str2, 并將結果放入 str1中 字符串連接函數(shù) strcat include include int main(void) { char str1[80], str2[20]。 gets(str2)。 puts(str1)。 } str1中: Let us \0 str2中: go.\0 str1中: Let us go.\0 str2中: go.\0 Let us go. Let us go. strcmp(str1, str2) 比較 兩個字符串 str1和 str2的大小。 字符串比較函數(shù) strcmp strcmp(s1, Sea)。 strcmp(Sea, Sea)。 char s1[20], s2[20]。 gets(s2)。 printf(“%d”, res)。 } strcmp() 示例 1234 5 4 利用字符串比較函數(shù)比較字符串的大小 strcmp(str1, str2)。 static char str[20]=“How are you?” strlen(“hello”) 的值是: strlen(str) 的值是: 字符串長度函數(shù) strlen 5 12 函數(shù) 功能 頭文件 puts(str) 輸出字符串 gets(str) 輸入字符串(回車間隔) strcpy(s1,s2) s2 == s1 strcat(s1,s2) s1 “+” s2 == s1 若 s1“==”s2, 函數(shù)值為 0 strcmp(s1,s2) 若 s1 “” s2, 函數(shù)值 0 若 s1 “” s2, 函數(shù)值 0 計算字符串的有效長度, strlen(str) 不包括 ‘ \0’ 字符串處理函數(shù)小結 int main( ) { int i。 scanf(%d, amp。 min = x。 i 5。x)。 } printf(min is %d\n, min)。 } 例 816 求最小字符串 include int main( ) { int i。 scanf(%s, sx)。 for(i = 1。 i++){ scanf(%s, sx)。 } printf(min is %s\n, smin)。 } 2 8 1 99 0 min is –1 tool key about zoo sea min is about 任意個整數(shù)求和問題 * 例 817 先輸入一個正整數(shù) n, 再輸入任意 n個整數(shù),計算并輸出這 n個整數(shù)的和。 程序解析 int main ( ) { int n, sum, i, *p。 scanf(%d, amp。 if ((p = (int *) calloc (n, sizeof(int))) == NULL) { printf(Not able to allocate memory. \n)。 } printf(Enter %d integers: , n)。 i n。 sum = 0。 i n。 printf(The sum is %d \n,sum)。 return 0。 ? 自動變量 ,在執(zhí)行進入變量定義所在的復合語句時為它們分配存儲,變量的大小也是靜態(tài)確定的。 動態(tài)存儲管理 ? 不是由編譯系統(tǒng)分配的,而是由用戶在程序中通過動態(tài)分配獲取。 ( 3) 使指針指向獲得的內存空間 , 以便用指針在該空間內實施運算或操作 。 動態(tài)存儲分配函數(shù) malloc() void *malloc(unsigned size) 在內存的動態(tài)存儲區(qū)中分配一連續(xù)空間,其長度為size ?若申請成功,則返回一個指向所分配內存空間的起始地址的指針 ?若申請內存空間不成功,則返回 NULL( 值為 0) ?返回值類型: (void *) ? 通用指針的一個重要用途 ? 將 malloc的返回值轉換到特定指針類型,賦給一個指針 malloc()示例 /* 動態(tài)分配 n個整數(shù)類型大小的空間 */ if ((p = (int *)malloc(n*sizeof(int))) == NULL) { printf(“Not able to allocate memory. \n”)。 } ? 調用 malloc時,用 sizeof 計算存儲塊大小 ? 每次動態(tài)分配都要檢查是否成功,考慮例外情況處理 ? 雖然存儲塊是動態(tài)分配的,但它的大小在分配后也是確定的,不要越界使用。 當某個動態(tài)分配的存儲塊不再用時,要及時將它釋放 分配調整函數(shù) realloc void *realloc(void *ptr, unsigned size) 更改以前的存儲分配 ? ptr必須是以前通過動態(tài)存儲分配得到的指針 ? 參數(shù) size為現(xiàn)在需要的空間大小 ? 如果調整失敗,返回 NULL,同時原來 ptr指向存儲塊的內容不變。如果 size小于原塊的大小,則內容為原塊前 size范圍內的數(shù)據;如果新塊更大,則原有數(shù)據存在新塊的前一部分。
點擊復制文檔內容
物理相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1