=== Basics ===
> simple statements are commands
> block statements are surrounded by { and }
> if statements run code if something is true
> switch statements efficiently check for multiple values of a variable
> you can combine conditions together with $$ and ||
> every program needs a main founction
> #include include external code for things like input and output
> your source files should have a name ending in .c
> you need to compile your C program before you run it
> gcc is the most popular C compiler
> you can use the $$ operator on the command line to only run your program if it compiles
> -o specifies the output file
> count++ means add 1 to count
> count-- means subtract 1 from count
> while repeats code as long as a condition is true
> do-while loops run code at least once
> for loops are a more compact way of writing loops
=== Pointers and memory ===
> scanf("%i", $x) will allow a user to enter a number x directly
> a char pointer variable x is declared as char *x
> initialize a new array with a string, and it will copy it
> $x is called a pointer to x
> $x returns the address of x
> array variables can be used as pointers
> read the contents of an address a with *a
> fgets(buf, size, stdin) is a simpler way to enter text
> local variable are stored on the stack
=== Strings ===
> literal strings are stored in read-only memory
> the string.h header contains useful string functions
> an array of strings is an array of arrays
> you create an array of arrays using char strings[][]
> strstr(a, b) will return the address of string b in string a
> strcmp() compares two strings
> strcat() concatenates two string together
> strchr() finds the location of a character inside a string
> strcpy() copies one string to another
> strlen() finds the length of a string
=== Data streams ===
> C functions like printf() and scanf() use the Standard Output and Standard Input to communicate
> the Standard Output goes to the display by default
> the Standard Input reads from the keyboard by default
> you can change where the Standard Input, Output, and Error are connected to using redirection
> the Standard Error is a separate output intended for error messages
> you can print to the Standard Error using fprintf(stderr, ...)
> you can create custom data streams with fopen("filename", mode)
> the mode can be "w" to write, "r" to read, or "a" to append
> command-line arguments are passed to main() as an array of string pointers
> the getopt() function makes it easier to read command-line options
=== Data types ===
> chars are nubmers
> use longs for really big whole numbers
> use shorts for small whole numbers
> use ints for most whole numbers
> ints are different sizes on different machines
> use floats for most floating points
> use doubles for really precise floating points
=== Multiple files ===
> split function declarations from definitions
> put declarations in a header file
> #include <> for library headers
> #include "" for local headers
> save object code into files to speed up your builds
> use make to manage your builds
=== Compilation behind the scenes ===
1. Preprocessing: fix the source
2. Compilation: translate into assembly
3. Assembly: generate the object code
4. Linking: put it all together
=== Structs ===
> a struct combines data types together
> you can read struct fields with dot notation
> you can initialize structs with {array, like, notation}
> -> notation lets you easily update fields using a struct pointer
> typedef lets you create an alias for a data type
> designated initializers let you set struct and union fields by name
=== Unions and bitfields ===
> unions can hold different data types in one location
> enums let you create a set of symbols
> bitfields give you control over the exact bits stored in a struct
=== Data structures ===
> dynamic data structures use recursive structs
> recursive structs contain one or more links to similar data
> a linked list is a dynamic data structure
> data can be inserted easily into a linked list
> a linked list is more extensible than an array
=== Dynamic memory ===
> the stack is used for local variables
> unlike the stack, heap memory is not automatically released
> malloc() allocates memory on the heap
> free() releases memory on the heap
> strdup() will create a copy of a string on the heap
> a memory leak is allocated memory you can no longer access
> valgrind can help you track down memory leaks
=== Advanced functions ===
> function pointers let you pass functions around as if they were data
> function pointers are the only pointers that don't need the * and $ operators, but you can use them if you want to
> the name of every function is a pointer to the function
> qsort() will sort an array
> each sort function needs a pointer to a comparator function
> comparator functions decide how to order two pieces of data
> arrays of function pointers can help run different functions for different types of data
> functions with a variable number of arguments are called "variadic"
> stdarg.h lets you create variadic functions
=== Static and dynamic libraries ===
> #include <> looks in standard directories such as /usr/include
> -L<name> adds a directory to the list of standard library directories
> -1<name> links to a file in standard directories such as /usr/lib
> -I<name> adds a directory to the list of standard include directories
> the ar command creates a library archive of object files
> library archives have names like libsomething.a
> library archives are statically linked
> "gcc -shared" converts object files into dynamic libraries
> dynamic libraries are linked at runtime
> dynamic libraries have different names on different operting systems
> dynamic libraries have .so, .dylib, .dll, or .dll.a extensions
=== Processes and commumication ===
> system() will run a string like a console command
> fork() duplicates the current process
> fork() + exec() creates a child process
> execl() = list of args
execle() = list of args + environment
execlp() = list of args + search on path
execv() = arrary of args
execve() = arrary of args + environment
execvp() = array of args + search on path
> processes can communicate using pipe
> pipe() creates a communication pipe
> exit() stops the program immediately
> waitpid() waits for a process to finish
> fileno() finds the descriptor
> dup2() duplicates a data stream
> signals are messages from the O/S
> sigaction() lets you handle signals
> a program can send signals to itself with raise()
> alarm() sends a SIGALRM after a few seconds
> the kill command sends a signal
> simple processes do one thing at a time
=== Sockets and networking ===
> telnet is a simple network client
> create sockets with the socket() function
> servers BLAB:
B = bind()
L = listen()
A = accept()
B = begin talking
> use fork() to cope with serval clients at once
> DNS = domain name system
> getaddrinfo() finds addresses by domain
=== Threads ===
> threads allow a process to do more than one thing at the same time
> threads are "lightweight processes"
> POSIX threads (pthread) is a threading library
> pthread_create() creates a thread to run a function
> pthread_join() will wait for a thread to finish
> threads share the same global variables
> if two threads read and update the same variable, your code will be upredictable
> mutexes are locks that protect shared data
> pthread_mutex_lock() creates a mutex on code
> pthread_mutex_unlock() releases the mutex
重要知识点摘记
《嗨翻C语言》热门书评
-
Head First C
5有用 0无用 maybepossible 2014-01-11
初见是在图书馆的新书书架上,中文版译作“嗨翻C语言”。当时心里想有没有必要这么“俗”的起名啊……不过还好我拿了起来。C语言学了好几年了,虽不是计算机专业的但平常也都在编程,看了目录就知道这本书很对胃口,不仅是因为行文说理生动透彻,也因为其知识点设计的实用。现在看卖了几千万册的谭浩强老爷子的书真是弱爆...
-
不要买电子版,不要买电子版,不要买电子版,重要的事情说3遍
2有用 1无用 SCV就绪 2015-09-09
这本书可以说是我目前看过的最让人愿意看下去的C语言书籍。整本书写的非常的幽默(给译者点个赞),而且不像其他书一样列10几个例题在那自己去研究。每一道例题都是一道题。但是,该书难度比较高,至少在我看来,如果完全没有学过C语言,这本书学起来应该会比较吃力。至于为什么不要买电子版,因为这本书里有非常多的图...
-
看过谭浩强之后请回头看看这本书
2有用 0无用 宇卿 2014-04-01
想凭借一本书掌握一门语言精粹根本是一件不可能的事情。当然本书同样也不例外,但是一本c语言的书能够做到如此颠覆我对c类教科书的刻板印象,我想也只有这本head first c了,开篇不跟你胡扯一堆变量,各种语句,之类的...
-
流暢、自然
1有用 1无用 羊羽北 2012-06-15
作爲Head First系列的一員,這是一本很棒的書,書的內容組織很棒,知識點的引入非常自然和流暢,通俗易懂又不失深度,三個Lab的內容很有意思,值得多看幾遍。書尚未讀完,詳細評論待續。英文好的請移步amazon:http://www.amazon.com/gp/product/1449399916...
-
官方的试读~
1有用 2无用 瓦力 2013-08-21
网址:请尊重创作者的劳动,勿提供下载信息、或转载他人的文章。“Kathy和Bert的《深入浅出Java》把书本变成了图形界面。作者通过一种诙谐、嬉皮的调调,把学习Java变成了一个充满未知的过程,我总忍不住好奇地想:‘作者接下来会干嘛?’”——Warren Keuffel,《软件开发杂志》“《深入浅...
书名: 嗨翻C语言
作者:
出版社: 人民邮电出版社
原作名: Head First C
译者: 程亦超 | [美] Dawn Griffiths
出版年: 2013-9
页数: 630
定价: 99.00
装帧: 平装
丛书: O'Reilly深入浅出系列
ISBN: 9787115318848