]> zdv2.bktei.com Git - BK-2023-05.git/blobdiff - src/notes.tm
update(src/kr/s1.5):Add exercises
[BK-2023-05.git] / src / notes.tm
index c55e59ee91d37b291eb0a51d61c41002ff813e8f..0d4cac65d7c447da26bf10a84a3094b2b31007e4 100644 (file)
@@ -3,11 +3,53 @@
 <style|<tuple|book|style-bk>>
 
 <\body>
 <style|<tuple|book|style-bk>>
 
 <\body>
+  <\hide-preamble>
+    \;
+
+    <assign|description-aligned|<\macro|body>
+      <compound|<if|<and|<value|<merge|prefix-|description-aligned>>|<unequal|<value|last-item-nr>|0>>|list*|list>|<macro|name|<aligned-item|<item-strong|<arg|name><item-spc>>>>|<macro|name|<with|mode|math|<with|font-series|bold|math-font-series|bold|<rigid|\<ast\>>>>>|<arg|body>>
+    </macro>>
+  </hide-preamble>
+
   <chapter|Definitions>
 
   <section|Terminology>
 
   <\description-compact>
   <chapter|Definitions>
 
   <section|Terminology>
 
   <\description-compact>
+    <item*|assignment>An expression in which a variable is set to a value.
+    For example, in the expression <hgroup|<cpp|x = 1>>, the variable <cpp|x>
+    is set to the value <cpp|1> because <cpp|x> is to the left of the equals
+    sign \ \P<cpp|=>\Q. The value of the entire expression is equal to the
+    value of the left hand side (i.e. <cpp|x> in this example) after the
+    assignment is performed. For example, the following C code will print
+    \P<cpp|true>\Q:
+
+    <\cpp-code>
+      #include \<less\>stdio.h\<gtr\>
+
+      int main() {
+
+      \ \ int c;
+
+      \ \ if( (c = 7) == 7 )
+
+      \ \ \ \ printf("true");
+
+      \ \ else
+
+      \ \ \ \ printf("false");
+
+      };
+    </cpp-code>
+
+    As another example, the following lines are equivalent:
+
+    <\cpp-code>
+      a = b = c = 0;
+
+      a = ( b = ( c = 0 ) );
+    </cpp-code>
+
     <item*|declaration<label|term declaration>>A construct that establishes
     an association between a particular variable, function, or type and its
     attributes. (See <hlink|cppreference.com|https://en.cppreference.com/w/c/language/declarations>
     <item*|declaration<label|term declaration>>A construct that establishes
     an association between a particular variable, function, or type and its
     attributes. (See <hlink|cppreference.com|https://en.cppreference.com/w/c/language/declarations>
@@ -30,7 +72,7 @@
     used to represent hard-to-type or invisible characters. Some commonly
     used escape sequences in <name|C> include:
 
     used to represent hard-to-type or invisible characters. Some commonly
     used escape sequences in <name|C> include:
 
-    <\description-paragraphs>
+    <\description-aligned>
       <item*|<cpp|\\n>>Represents the <em|newline> character.
 
       <item*|<cpp|\\t>>Represents the <em|tab> character.
       <item*|<cpp|\\n>>Represents the <em|newline> character.
 
       <item*|<cpp|\\t>>Represents the <em|tab> character.
 
       <item*|<cpp|\\\\>>Represents the <em|backslash> (i.e.
       \P<verbatim|<em|\\>>\Q) character.
 
       <item*|<cpp|\\\\>>Represents the <em|backslash> (i.e.
       \P<verbatim|<em|\\>>\Q) character.
-    </description-paragraphs>
+    </description-aligned>
 
     All other escape sequences used in <name|C> are:
 
 
     All other escape sequences used in <name|C> are:
 
-    <\description-paragraphs>
+    <\description-aligned>
       <item*|<cpp|\\a>>Represents the <em|alert> (bell) character.
 
       <item*|<cpp|\\f>>Represents the <em|formfeed> character.
       <item*|<cpp|\\a>>Represents the <em|alert> (bell) character.
 
       <item*|<cpp|\\f>>Represents the <em|formfeed> character.
       <item*|<cpp|\\x><em|hh>>Represents a <em|hexadecimal> number (e.g.
       <cpp|\\x0A> is the <em|newline> character<rsup|<reference|ref
       includehelp-oct-hex>>).
       <item*|<cpp|\\x><em|hh>>Represents a <em|hexadecimal> number (e.g.
       <cpp|\\x0A> is the <em|newline> character<rsup|<reference|ref
       includehelp-oct-hex>>).
-    </description-paragraphs>
+    </description-aligned>
 
     <label|term garbage_collection><item*|garbage collection>The process of
     freeing memory allocated by a program but which is no longer referenced.
 
     <label|term garbage_collection><item*|garbage collection>The process of
     freeing memory allocated by a program but which is no longer referenced.
   <subsection|Character Input and Output>
 
   <\description>
   <subsection|Character Input and Output>
 
   <\description>
-    <item*|<cpp|getchar()><label|func getchar>>Read one character at a time.
+    <item*|<cpp|getchar()><label|func getchar>>Read one character at a time
+    from the input buffer. Returns as <cpp|int> a <em|character
+    constant>.<\footnote>
+      <name|ASCII> characters have constants in the range <math|0-127>. UTF-8
+      characters return multiple constants (e.g. \<#B0\> returns <cpp|194
+      176>). See <hlinkv|https://www.smashingmagazine.com/2012/06/all-about-unicode-utf8-character-sets/>.
+      A strategy for reading the multiple bytes of a UTF-8 character is here:
+      <hlinkv|https://stackoverflow.com/a/34240796/>.
+    </footnote>
 
     <item*|<cpp|for()>>A generalization of <cpp|while()>. Takes three
     arguments:
 
     <item*|<cpp|for()>>A generalization of <cpp|while()>. Takes three
     arguments:
       variable).
     </enumerate>
 
       variable).
     </enumerate>
 
-    <item*|<cpp|putchar()><label|func putchar>>Write one character at a time.
+    <item*|<cpp|putchar(int arg1)><label|func putchar>>Write one integer
+    character (e.g. <cpp|arg1>) at a time.
 
     <item*|<cpp|printf()>>Used for printing formatted text to console.
 
     <item*|<cpp|printf()>>Used for printing formatted text to console.
+
+    Character codes include:
+
+    <\description-aligned>
+      <item*|<cpp|%d>>Used with <cpp|int> (i.e. 16-bit integers; max value of
+      <math|2<rsup|16>=32\<space\>767>).
+
+      <item*|<cpp|%ld>>Used with <cpp|long> (i.e. at least 32-bit
+      integers).<\footnote>
+        K&R 2nd Ed., Sec. 1.5 \PThe conversion specification <cpp|%ld> tells
+        <cpp|printf> that the corresponding argument is a <cpp|long>
+        integer.\Q
+      </footnote>
+
+      <item*|<cpp|%f>>Used with <cpp|float> and <cpp|double> (double
+      precision <cpp|float>).
+    </description-aligned>
   </description>
 
   \;
   </description>
 
   \;
     <associate|auto-2|<tuple|1.1|?>>
     <associate|auto-3|<tuple|1.2|?>>
     <associate|auto-4|<tuple|1.2.1|?>>
     <associate|auto-2|<tuple|1.1|?>>
     <associate|auto-3|<tuple|1.2|?>>
     <associate|auto-4|<tuple|1.2.1|?>>
+    <associate|footnote-1|<tuple|1|?>>
     <associate|footnote-1.1.1|<tuple|1.1.1|?>>
     <associate|footnote-1.1.1|<tuple|1.1.1|?>>
-    <associate|footnote-1.1.2|<tuple|1.1.2|?>>
+    <associate|footnote-1.2.1|<tuple|1.2.1|?>>
+    <associate|footnote-1.2.2|<tuple|1.2.2|?>>
     <associate|footnr-1.1.1|<tuple|1.1.1|?>>
     <associate|footnr-1.1.1|<tuple|1.1.1|?>>
-    <associate|footnr-1.1.2|<tuple|1.1.2|?>>
+    <associate|footnr-1.2.1|<tuple|1.2.1|?>>
+    <associate|footnr-1.2.2|<tuple|1.2.2|?>>
     <associate|func getchar|<tuple|1.2.1|?>>
     <associate|func putchar|<tuple|3|?>>
     <associate|ref includehelp-oct-hex|<tuple|1.1.1|?>>
     <associate|func getchar|<tuple|1.2.1|?>>
     <associate|func putchar|<tuple|3|?>>
     <associate|ref includehelp-oct-hex|<tuple|1.1.1|?>>
-    <associate|term declaration|<tuple|1.1|?>>
+    <associate|term declaration|<tuple|assignment|?>>
     <associate|term definition|<tuple|declaration<label|term declaration>|?>>
     <associate|term enumeration|<tuple|definition<label|term definition>|?>>
     <associate|term escape_sequence|<tuple|enumeration<label|term
     enumeration>|?>>
     <associate|term definition|<tuple|declaration<label|term declaration>|?>>
     <associate|term enumeration|<tuple|definition<label|term definition>|?>>
     <associate|term escape_sequence|<tuple|enumeration<label|term
     enumeration>|?>>
-    <associate|term foo|<tuple|structure assignment|?>>
-    <associate|term garbage_collection|<tuple|1.1.1|?>>
+    <associate|term garbage_collection|<tuple|<with|mode|<quote|prog>|prog-language|<quote|cpp>|font-family|<quote|rm>|\\x><with|font-shape|<quote|italic>|hh>|?>>
     <associate|term heap|<tuple|garbage collection|?>>
     <associate|term machine-independent|<tuple|<label|term heap>heap|?>>
     <associate|term operand|<tuple|<label|term
     <associate|term heap|<tuple|garbage collection|?>>
     <associate|term machine-independent|<tuple|<label|term heap>heap|?>>
     <associate|term operand|<tuple|<label|term
     <associate|term struct|<tuple|<label|term stack>stack|?>>
     <associate|term structure_assignment|<tuple|<label|term struct>struct|?>>
     <associate|term text_stream|<tuple|structure assignment|?>>
     <associate|term struct|<tuple|<label|term stack>stack|?>>
     <associate|term structure_assignment|<tuple|<label|term struct>struct|?>>
     <associate|term text_stream|<tuple|structure assignment|?>>
-    <associate|term-sep XX|<tuple|structure assignment|?>>
   </collection>
 </references>
 
   </collection>
 </references>