原创 C語言基礎 -49 函數_函數與指針的關係

1 指針函數:本質是函數,函數的返回值是指針;對面需要定義一個指針來接收。 <之前的函數,返回值爲void/int等> //返回第num個同學的成績 book@100ask:~/C_coding/CH02$ cat func_po

原创 C語言基礎 -51 構造類型_結構體的定義變量及成員引用

book@100ask:~/C_coding/CH02$ cat strct.c #include <stdio.h> #include <stdlib.h> #define NAMESIZE 32 struct simp_st

原创 C語言基礎 -52 構造類型_結構體內存問題及函數傳參

book@100ask:~/C_coding/CH02$ cat struct1.c #include <stdio.h> #include <stdlib.h> #define NAMESIZE 32 struct simp_st

原创 C語言基礎 -50 構造類型_結構體的描述及嵌套

結構體:也是一段連續的存儲空間,存儲不同數據類型。 數組:連續的存儲空間,存儲相同數據類型 結構體的描述,不佔用任何存儲空間。 結構體的定義:類型  + 變量名 以上兩種嵌套定義的方式都可以,看使用習慣

原创 C語言基礎 -48 函數_函數與字符數組

#include <stdio.h> #include <stdlib.h> char *mystrcpy(char *dest, const char *src) { char *ret = dest; if(dest !=

原创 C語言基礎 -46 函數_函數與一維數組

普通數組 book@100ask:~/C_coding/CH02$ cat arr.c #include <stdio.h> int main() { int i; int a[] = {1,3,5,7,9}; for(i =

原创 C語言基礎 -47 函數_函數與二維數組

book@100ask:~/C_coding/CH02$ cat 2_arr.c #include <stdio.h> #include <stdlib.h> #define M 3 #define N 4 int main()

原创 C語言基礎 -34 指針_指針運算

&q  ---- 0x4000 q  ----> 0x3000 --- &p *q ---> *(&p) ---> p --- 0x2000 **q ---> *(*q) ---> *p ---> 1      *p: 取指針p指向的地

原创 C語言基礎 -35 指針_指針與一維數組

book@100ask:~/C_coding/CH01$ cat arr.c #include <stdio.h> #include <stdlib.h> int main() { int a[3] = {1,2,3}; int

原创 C語言基礎 -45 函數_使用遞歸解決階乘與斐波那契問題

book@100ask:~/C_coding/CH02$ cat fun.c #include <stdio.h> #include <stdlib.h> int func(int n) { if(n < 0) return -

原创 C語言基礎 -43 函數_嵌套

book@100ask:~/C_coding/CH02$ cat test.c #include <stdio.h> #include <stdlib.h> int dist(int a,int b,int c) { retu

原创 C語言基礎 -30 數組_字符數組輸入與輸出常用函數

book@100ask:~/C_coding/CH01$ cat char1.c #include <stdio.h> #include <stdlib.h> #define N 32 int main() { char str[

原创 C語言基礎 -33 指針_指針與變量的關係

變量i,值爲1,存放值1的地址爲0x2000 地址:房間, 內容:key P存放的內容是i的地址,及p - &i &p:指針p的地址爲0x3000 p的內容,*p,指向地址0x2000裏面的內容,即1 book@100ask:~/C

原创 C語言基礎 -44 函數_遞歸

遞歸:一個函數直接或間接調用自己,是嵌套的特例 book@100ask:~/C_coding/CH02$ cat func.c #include <stdio.h> #include <stdlib.h> void a(void)

原创 C語言基礎 -31 數組_單詞計數

book@100ask:~/C_coding/CH01$ cat wordcount.c #include <stdio.h> int main() { printf("輸入一行字符:\n"); char ch;