The C Programming Language

1. A #define line defines a symbolic name or symbolic constant to be a particular string of characters: (P14)

  #define         name        replacement text

Notice that there is no semicolon at the end of a #define line.

2. getchar() reads the next input character from a text stream and returns that as its value. That is, after  (P15)

 c = getchar()

the variable c contains the next character of input.

3. (Call by value) The main distinction is that in C the called function cannot directly alter a variable in the calling function; it can only alter its private, temporary copy. (P27)

4. automatic variables

     external variables

In fact, common practice is to place definitions of all external variables at the beginning of the source file, and then omit all extern declarations. (P33)

5. "definition" refers to the place where the variable is created or assigned storage;

    "declaration" refers to the places where the nature  of the variable is stated but no storage is allocated. (P33)

6. Precedence and associativity of operators  (P53)

Precedence and associativity of operators
OperatorsAssociativity
   ( )    [ ]   ->   . left to right
   !   ~  ++   --    +    -   *   &      (type)      sizeof right to left
   *                 /                % left to right
   +       - left to right
  <<                >> left to right
  <         <=            >            >= left to right
  ==             != left to right
   & left to right
  ^ left to right
  | left to right
  && left to right
  || left to right
  ?: right to left
  =   +=  -=  *=  /=  %=  &=  ^=  |=  <<=   >>= right to left
  , left to right

7.  The value of *t++ is the character that t pointed to before t was incremented; the postfix ++ doesn't change t until after this character has been fetched. (P105)

/* strcpy: copy t to s; pointer version 3 */
void strcpy(char *s, char *s)
{ 
     while (*s++ = *t++)
          ;
}
8. In fact, the pair of expressions (P106)
  *p++ = val;   /* push val onto stack */
  val = *--p;    /* pop top of stack into val */

The first is similar to *p = val, p++; the second expression associativity is right to left.

In the same way, *p->str fetches whatever str points to; *p->str++ increments str after accessing whatever it points to (just like *s++); (*p->str)++ increments whatever str points to; and *p++->str increments p after accessing whatever str points to. (P132)

9.  # define NKEYS    (sizeof keytab  / sizeof keytab[0])

  or #define NKEYS  (sizeof keytab / sizeof(struct key))

   A sizeof can not be used in a #if line, because the preprocessor does not parse type name. But the expression in the #define is not evaluated by the preprocessor, so the code here is legal.  (P135)

10. Besides purely aesthetic issues, there are two main reasons for using typedefs. The first is to parameterize a program against portability problems. If typedefs are used for data types that may be machine-dependent, only the typedefs need change when the program is moved. One common situation is to use typedef names for various integer quantities, then make an appropriate set of choices of short, int, and long for each host machine. Types like size_t and ptrdiff_t from the standard library are examples.

The second purpose of typedefs is to provide better documentation for a program-- a type called Treeptr may be easier to understand than one declared only as a pointer to a complicated structure. (P147)

11. In effect, a union is structure in which all members have offset zero from base, the structure is big enough to hold the "widest" member, and the alignment is appropriate for all of the types in the union.

A union may only be initialized with a value of the type of its first member. (P148)

12. A bit-field, or filed for short, is a set of adjacent bits within a single implementation-defined storage unit that we will call a "word". The syntax of field definition and access is based on structures. (P149)

Almost everything about fields is implementation-dependent. Whether a field may overlap a word boundary is implementation-defined. Fields need not be named; unnamed fields( a colon and width only) are used for padding. The special width 0 may be used to force alignment at the next word boundary. (P150)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The C programming Language By Brian W. Kernighan and Dennis M. Ritchie. Published by Prentice-Hall in 1988 ISBN 0-13-110362-8 (paperback) ISBN 0-13-110370-9 目录结构: Contents Preface Preface to the first edition Introduction Chapter 1: A Tutorial Introduction Getting Started Variables and Arithmetic Expressions The for statement Symbolic Constants Character Input and Output File Copying Character Counting Line Counting Word Counting Arrays Functions Arguments - Call by Value Character Arrays External Variables and Scope Chapter 2: Types, Operators and Expressions Variable Names Data Types and Sizes Constants Declarations Arithmetic Operators Relational and Logical Operators Type Conversions Increment and Decrement Operators Bitwise Operators Assignment Operators and Expressions Conditional Expressions Precedence and Order of Evaluation Chapter 3: Control Flow Statements and Blocks If-Else Else-If Switch Loops - While and For Loops - Do-While Break and Continue Goto and labels Chapter 4: Functions and Program Structure Basics of Functions Functions Returning Non-integers External Variables Scope Rules Header Files Static Variables Register Variables Block Structure Initialization Recursion The C Preprocessor File Inclusion Macro Substitution Conditional Inclusion Chapter 5: Pointers and Arrays Pointers and Addresses Pointers and Function Arguments Pointers and Arrays Address Arithmetic Character Pointers and Functions Pointer Arrays; Pointers to Pointers Multi-dimensional Arrays Initialization of Pointer Arrays Pointers vs. Multi-dimensional Arrays Command-line Arguments Pointers to Functions Complicated Declarations Chapter 6: Structures Basics of Structures Structures and Functions Arrays of Structures Pointers to Structures Self-referential Structures Table Lookup Typedef Unions Bit-fields Chapter 7: Input and Output Standard Input and Output Formatted Output - printf Variable-length Argument Lists Formatted Input - Scanf File Access Error Handling - Stderr and Exit Line Input and Output Miscellaneous Functions String Operations Character Class Testing and Conversion Ungetc Command Execution Storage Management Mathematical Functions Random Number generation Chapter 8: The UNIX System Interface File Descriptors Low Level I/O - Read and Write Open, Creat, Close, Unlink Random Access - Lseek Example - An implementation of Fopen and Getc Example - Listing Directories Example - A Storage Allocator Appendix A: Reference Manual Introduction Lexical Conventions Syntax Notation Meaning of Identifiers Objects and Lvalues Conversions Expressions Declarations Statements External Declarations Scope and Linkage Preprocessor Grammar Appendix B: Standard Library Input and Output: <stdio.h> File Operations Formatted Output Formatted Input Character Input and Output Functions Direct Input and Output Functions File Positioning Functions Error Functions Character Class Tests: <ctype.h> String Functions: <string.h> Mathematical Functions: <math.h> Utility Functions: <stdlib.h> Diagnostics: <assert.h> Variable Argument Lists: <stdarg.h> Non-local Jumps: <setjmp.h> Signals: <signal.h> Date and Time Functions: <time.h> Implementation-defined Limits: <limits.h> and <float.h> Appendix C: Summary of Changes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值