- This is a Linux c programming learning notebook
- Ref:
Linux C编程一站式学习
C语言程序设计 The C Programming Language
- os
- Ubuntu 16.04 LTS
- compiler
- gcc version 9.4.0
-
char is a short integer, only 1B(8 bit)
-
type conversion(or typecasting)
int a = '1' - '0' /* char int to digit */ printf("%d\n", a);
-
char array, refers array storing chars
char ca[];
-
void * can be casted to any pointer without losing information
-
pointer is a variable, hexademical int, different to array name
int ia[4] = {0, 1, 2, 3}; int *pa = ia; pa++ /* right */ ia++ /* wrong, only variable can*/
-
Store many different type variables
struct Pointer { int x = 0; int y = 0; }; /* struct Pointer */ struct Pointer p; /* instantiation */
-
function returning a pointer
Void *fun(int);
-
pointer to a function
void (*pfun) (int);
-
function parameter
void fun(char s[]); void fun(char *s); /* char s[] same as char *s and char *s mostly used */
-
pointer array, refers to array storing pointers
int *ia[100]; char *ca[100] = {"string", "hello", "world"}; /* mostly used to save string */ printf("%s %s %s\n", ca[0], ca[1], ca[2], ca[3]);
-
pointer to an array
int (*pa)[100];
-
array name, refers to a pointer to the first element of array
int ia[10]; printf("%p %p", ia, &ia[0]) /* ia same as &ia[0]; */
-
index, refers to dereference address
/* ia[i] same as *(ia + i) */