home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 January / DPPCPRO0198.ISO / extras / nowucit / GLOSSARY.TXT < prev    next >
Encoding:
Text File  |  1997-05-07  |  22.0 KB  |  795 lines

  1. Array
  2. Assignment
  3. Bit
  4. Break
  5. Byte
  6. C
  7. C++
  8. Case
  9. Char
  10. Continue
  11. Declare
  12. Default
  13. Define
  14. Do
  15. Double
  16. Else
  17. Enum
  18. Expression
  19. Float
  20. Function
  21. Goto
  22. If
  23. Index
  24. Int
  25. Long
  26. Loop
  27. Main
  28. Operators
  29. PAC Software
  30. Pointer
  31. Prototype
  32. Short
  33. Statement
  34. String
  35. Struct
  36. Switch
  37. Variable
  38. Void
  39. While
  40. *Array
  41. An array is a series of values, which can be treated
  42. as a group.  For example, the following declares
  43. an array of 10 integers:
  44.  
  45.     int a[10];
  46.  
  47. The name of the array is "a".  To assign a value to the
  48. first of the integers, you could use a statement like this:
  49.  
  50.     a[0] = 52;
  51.  
  52. To assign a value to the last of the 10 integers, you would
  53. use:
  54.  
  55.     a[9] = 97;
  56.  
  57. The value within the brackets is called the "index".  It
  58. indicates which of the integers you are using.  It can
  59. be a constant, as in the examples above, or an expression,
  60. like this:
  61.  
  62.     a[5*i] = 19;
  63.  
  64. You can use an array value anyplace you use a regular
  65. variable.  For example:
  66.  
  67.     total = a[5] + a[6];
  68. *Assignment
  69. C allows you to assign a value to a variable like this:
  70.  
  71.     a = 5;
  72.  
  73. This example assigns the value "5" to the variable "a".  You
  74. can use an assignment within an expression, like this:
  75.  
  76.     b = (a=5)+2;
  77.  
  78. This example assigns "5" to "a", then adds 5 to 2 yielding 7,
  79. and finally assigns that 7 to b.
  80. *Bit
  81. A bit is the smallest unit of information storage.  Each bit can
  82. have only two possible states, usually referred to as "0" or "1".  (The
  83. states are also called "off" and "on".)  Bits are combined together
  84. in a computer to store information.
  85. *Break
  86. A "break" statement can be used two places.
  87.  
  88. The first place is within a do, while, or for loop.  In this
  89. case, it causes the loop to end, and the program resumes
  90. execution following the end of the loop.  Here's an example:
  91.  
  92.     int i;
  93.     int sum=0;
  94.     for (i=0; i<10; ++i) {
  95.         sum += i;
  96.         if (sum > 100) {
  97.             break;
  98.         }
  99.     }
  100.     sum += 5;
  101.  
  102. Here, if the value of "sum" exceeds 100, the "break" statement
  103. will be executed.  In that case, the "for" loop will end, and
  104. the program will continue running with the "sum += 5" statement.
  105.  
  106. The second place a "break" statement can be used is in a "switch"
  107. statement.  It marks the end of the code which is executed for a
  108. given case.  Here's an example:
  109.  
  110.     switch (a) {
  111.  
  112.     case 5:
  113.         b += 5;
  114.         c += 6;
  115.         break;
  116.  
  117.     case 6:
  118.         c = 2;
  119.         break;
  120.  
  121.     default:
  122.         e = 19;
  123.         break;
  124.     }
  125. *Byte
  126. A collection of bits.  Most commonly, a byte is 8 bits, which
  127. is enough to store one character using the ASCII coding
  128. system for characters.
  129. *C
  130. "C" is the third letter of the alphabet.
  131.  
  132. Perhaps more interesting, it is also a computer programming
  133. language developed by Dennis Ritchie.
  134. *C++
  135. "C++" is a language based on "C", but which incorporates
  136. several enhancements.  The most significant enhancement is
  137. the addition of object-oriented programming constructs.
  138.  
  139. Almost everything you learn on this CD about C is also true
  140. for C++, so C is a good first step toward learning the
  141. more complex C++.
  142. *Case
  143. The "case" statement is used within a "switch"
  144. statement to indicate what code should be executed
  145. for a given value.
  146.  
  147. For example, consider this "switch" statement:
  148.  
  149.     switch (a) {
  150.  
  151.     case 5:
  152.         b=6;
  153.         break;
  154.  
  155.     case 10:
  156.         b=19;
  157.         c=22;
  158.         break;
  159.  
  160.     default:
  161.         b=0;
  162.         break;
  163.     }
  164.  
  165. The "switch" statement causes the expression "a" to be
  166. evaluated.  It's value will determine which of the other
  167. statements are executed.
  168.  
  169. If "a" has a value of 5, the statement "b=6" will be
  170. executed.
  171.  
  172. If "a" has a value of 10, the statements "b=19" and "c=22"
  173. will be executed.
  174.  
  175. If "a" has any value other than 5 or 10, the statement "b=0" will
  176. be executed.
  177. *Char
  178. "char" is one of the basic data types in C.  It describes
  179. a value large enough to hold a single character.  In most cases,
  180. a char variable is 8 bits in size.
  181.  
  182. Although char variables are generally used to hold characters,
  183. they can also be used to hold small integers.
  184. *Continue
  185. A "continue" statement can be used within a do, while, or for loop.  It
  186. causes a jump to the top of the loop.  Here's an example:
  187.  
  188.     int i;
  189.     int sum=0;
  190.     int product=0;
  191.     for (i=0; i<10; ++i) {
  192.         sum += i;
  193.         if (product > 100) {
  194.             continue;
  195.         }
  196.         product *= i;
  197.     }
  198.     sum += 5;
  199.  
  200. Here, the statement "sum += i" will be executed every time
  201. through the loop (that is, 10 times).  But, the statement
  202. "product *= i" will be skipped if product exceeds 100.  When
  203. the "continue" statement is executed, the rest of the statements
  204. in the loop are skipped, but the loop continues.
  205. *Declare
  206. There are two similar but different terms in C, which are
  207. easily confused:  declare and define.  Here are examples of
  208. each:
  209.  
  210.     int sum(int a);
  211.          .
  212.          .
  213.          .
  214.     int sum(int a) {
  215.         int sum=0;
  216.         int i;
  217.         for (i=0; i<a; ++i) {
  218.             sum += i;
  219.         }
  220.         return sum;
  221.     }
  222.  
  223. In this example, the first statement ("int sum(int a);") DECLARES
  224. the function.  That is, it tells the compiler the functions name,
  225. return type, and parameters.  The later statements (beginning
  226. with "int sum(int a) {") DEFINE the function, giving the compiler
  227. the actual statements to be executed when the function is called.
  228.  
  229. The declaration of the function is also called its "prototype".
  230.  
  231. Variables can also be "declared".  For example, the statement
  232. "int i;" in the above example declares the variable "i".
  233. *Default
  234. This statement is part of a "switch" statement.  It
  235. identifies the code that should be executed if none of
  236. the other cases match.  For example:
  237.  
  238.     switch (a) {
  239.  
  240.     case 5:
  241.         b=6;
  242.         break;
  243.  
  244.     case 10:
  245.         b=19;
  246.         c=22;
  247.         break;
  248.  
  249.     default:
  250.         b=0;
  251.         break;
  252.     }
  253.  
  254. Here, the "b=0" statement will be executed if "a" is
  255. not 5 and "a" is not 10.
  256. *Define
  257. There are two similar but different terms in C, which are
  258. easily confused:  declare and define.  Here are examples of
  259. each:
  260.  
  261.     int sum(int a);
  262.          .
  263.          .
  264.          .
  265.     int sum(int a) {
  266.         int sum=0;
  267.         int i;
  268.         for (i=0; i<a; ++i) {
  269.             sum += i;
  270.         }
  271.         return sum;
  272.     }
  273.  
  274. In this example, the first statement ("int sum(int a);") DECLARES
  275. the function.  That is, it tells the compiler the functions name,
  276. return type, and parameters.  The later statements (beginning
  277. with "int sum(int a) {") DEFINE the function, giving the compiler
  278. the actual statements to be executed when the function is called.
  279.  
  280. The declaration of the function is also called its "prototype".
  281. *Do
  282. This statement causes a loop to occur.  Here is an example:
  283.  
  284.     do {
  285.         i += 20;
  286.     } while (i < 100);
  287.  
  288. In this case, the statement inside the loop ("i += 20") will
  289. be executed over and over until the condition ("i < 100") is 
  290. no longer true.
  291.  
  292. It is important to understand the difference between a "do"
  293. loop and a "while" loop.  Here's an example of a "while" loop:
  294.  
  295.     while (i < 100) {
  296.         i += 20;
  297.     }
  298.  
  299. This code does *almost* the same thing as the earlier example,
  300. but with one difference:  the earlier example will execute the
  301. statement inside the loop ("i += 20") at least once, no matter
  302. what value "i" had before the loop began.  The second example
  303. would not execute the interior of the loop even once if "i"
  304. was already greater than 100.
  305. *Double
  306. This is one of the basic data types in C.  It stores a
  307. floating-point number.  Here is an example of how to
  308. declare a variable of this type:
  309.  
  310.     double sum;
  311. *Else
  312. This statement is used along with an "if" statement to provide
  313. code to be executed if the condition in the "if" is false.  Here's
  314. an example:
  315.  
  316.     if (a < 5) {
  317.         b = 7;
  318.     } else {
  319.         b = 8;
  320.     }
  321.  
  322. In this example, "a" will be compared to "5".  If it is less, "7"
  323. will be assigned to "b"; if it isn't less, "8" will be assigned
  324. to "b".
  325.  
  326. An "else" statement can appear only right after an "if".  It can
  327. include braces, as in the above example, or not.  The braces are
  328. required if more than one statement is to be controlled by the "else",
  329. as in this example:
  330.  
  331.     if (sum < total) {
  332.         sum += value;
  333.     } else {
  334.         total = 0;
  335.         goal = reached;
  336.     }
  337. *Enum
  338. An "enum" is a type of data which can be declared in C.  In a sense,
  339. it allows you to declare your own data types.  Here's an example:
  340.  
  341.     enum tempurature {
  342.         hot,
  343.         normal,
  344.         cool
  345.     };
  346.  
  347. This defines an enum type named "temperature".  You can then declare
  348. variables of this type like this:
  349.  
  350.     enum temperature a;
  351.  
  352. You can assign values to the variable like this:
  353.  
  354.     a = hot;
  355.  
  356. It is common to use "typedef" with "enum", like this:
  357.  
  358.     typedef enum {
  359.         hot,
  360.         normal,
  361.         cool
  362.     } temperature;
  363.  
  364. Now a variable of this type can be declared more compactly:
  365.  
  366.     temperature a;
  367. *Expression
  368. An "expression" is a collection of constants and variables, combined with
  369. operators.  For example:
  370.  
  371.     a + 5
  372.  
  373. In this expression, "a" is a variable, "5" is a constant, and "+" is an operator.  This
  374. expression causes the compiler to obtain the value of "a", and add 5 to it.
  375.  
  376. Expressions are used in many C statements.  For example:
  377.  
  378.     b = a + 5;
  379.  
  380. This takes the value of the expression and stores it in the variable "b".
  381.  
  382. Expressions can be very simple:
  383.  
  384.     c
  385.  
  386. or very compilicated:
  387.  
  388.     c * f[22] / 19.5 >> (a > b ? 2 : 1)
  389. *Float
  390. This is one of the basic data types in C.  It stores a
  391. floating-point number.  Here is an example of how to
  392. declare a variable of this type:
  393.  
  394.     float sum;
  395. *Function
  396. A C program is often divided into pieces called "functions".  Each
  397. function performs a small bit of work, and the program combines them
  398. together to perform a larger piece of work.
  399.  
  400. Here is an example of a function:
  401.  
  402.     int add(int a,int b) {
  403.         if (a == 0) {
  404.             return 0;
  405.         }
  406.         if (b == 0) {
  407.             return 0;
  408.         }
  409.         return a+b;
  410.     }
  411.  
  412. Data is passed to the function, it performs some work, and it then
  413. returns a value.  In this case, two integers ("a" and "b") are passed
  414. to the function, and an integer is returned.
  415.  
  416. To cause the function to be executed, it is "called" from another place
  417. in the program.  Here is an example of calling the above function:
  418.  
  419.     sum = add(5,q);
  420.  
  421. This would cause the function to be executed with "a" having a value of
  422. "5", and "b" having the same value as the variable "q".  The value
  423. calculated by the function will be returned and placed in "sum".
  424. *Goto
  425. Normally, a C funciont is executed one statement at a time, starting
  426. at the top and working down to the bottom.  The "goto" statement is
  427. one of several C statements that allow you to change this order.  It
  428. causes execution to continue with a different statement.  Here is
  429. an example:
  430.  
  431.              a = 5;
  432.              if (b > 6) {
  433.                  goto wrapup;
  434.              }
  435.              c = sum(5,22);
  436.              e = sum(c,22);
  437.     wrapup:  f = 0;
  438.  
  439. The word "wrapup" is called a "label", and is used to identify the
  440. statement to be executed next.  In this example, if "b" is greater than
  441. "6", the "goto" statement will be executed.  That causes the program
  442. to skip past the other two statements and execute "f=0".
  443. *If
  444. The "if" statement in C allows you to have one or more statements executed
  445. only if a certain condition is met.  For example:
  446.  
  447.     if (a > 5)
  448.         c = 0;
  449.  
  450. This example will set "c" to "0" only if the condition ("a > 5") is true.
  451.  
  452. An "if" statement can effect just one statement, as in the above example.  It
  453. can also effect several statements by including those statements in
  454. braces, like this:
  455.  
  456.     if (a > 5) {
  457.         c = 0;
  458.         e = 5;
  459.     }
  460.  
  461. In this example, both of the statements ("c = 0" and "e = 5") will be executed
  462. only if the condition ("a > 5") is true.
  463. *Index
  464. An "index" is a value that determines which element of an array is used.  For
  465. example, suppose you have an array of 10 integers, like this:
  466.  
  467.     int a[10];
  468.  
  469. You can assign a value to the first of those 10 integers like this:
  470.  
  471.     a[0] = 55;
  472.  
  473. In this case, the "0" indicates which of the integers you are working
  474. with, and it is called the "index".
  475. *Int
  476. This is one of the basic data types in C.  It identifies a variable
  477. which can hold an integer value (that is, a whole number).
  478.  
  479. For example, here is an integer variable:
  480.  
  481.     int a;
  482.  
  483. The variable "a" could hold values like "5" or "-22" (but not "1.34").
  484. *Long
  485. The "long" keyword can be used when declaring integers or doubles.  It
  486. can cause additional storage to be used for the variable, giving it a
  487. greater possible range of values.
  488.  
  489. For example, here is a regular integer:
  490.  
  491.     int a;
  492.  
  493. and here is a long integer:
  494.  
  495.     long int b;
  496.  
  497. It is up to the compiler to decide how long each of these variables is.  In
  498. fact, the compiler *may* decide they will both be the same length.  But a
  499. "long int" is always at least as large as an "int".
  500.  
  501. Here is an example of a "double" and a "long double" variable:
  502.  
  503.     double c;
  504.     long double d;
  505.  
  506. A "long double" is commonly longer than a "double", but again the compiler
  507. can decide how long each will be.
  508. *Loop
  509. A "loop" is a set of statements which will be executed over and over.  For
  510. example:
  511.  
  512.     int i;
  513.     int sum=0;
  514.     for (i=0; i<10; ++i) {
  515.         sum += i;
  516.     }
  517.  
  518. This is a "loop" because it executes the statement "sum += i" 10 times.
  519. *Main
  520. C programs always begin with the computer executing one function in the
  521. program.  In standard C, this function is named "main".  Because of this,
  522. all standard C programs must include a function named "main" so the
  523. program will have a starting point.
  524.  
  525. There are some environments in which this rule doesn't apply.  For example,
  526. if you are writing a program for Microsoft Windows (not DOS), the program
  527. will begin with a function named "WinMain" instead of "main".
  528. *Operators
  529. An "operator" is a symbol which indicates that a certain
  530. operation should be performed on one or more values.  For example,
  531. here is an expression:
  532.  
  533.     a + 5
  534.  
  535. This expression includes the operator "+" which causes the value
  536. of variable "a" to be added to "5".
  537. *PAC Software
  538. PAC Software, Inc. is a small consulting company in
  539. Denver, Colorado.  This CD, along with others, was
  540. developed by the staff at PAC.
  541.  
  542. You can obtain further information about PAC from the
  543. web page at www.pacsoftware.com.
  544.  
  545. The name "PAC" stands for "Piece A Cake".
  546. *Pointer
  547. A pointer is a type of C variable that references a storage location.  For
  548. example, you can declare an integer variable like this:
  549.  
  550.     int a;
  551.  
  552. You can declare an integer pointer like this:
  553.  
  554.     int *b;
  555.  
  556. You can then make the pointer "point" to the storage location
  557. used by the integer "a" like this:
  558.  
  559.     b = &a;
  560.  
  561. (The "&" means "address of".)  Now that "b" is pointing to "a",
  562. you can use it to change the value of "a", like this:
  563.  
  564.     *b = 5;
  565.  
  566. The "*" means "the thing the pointer points to", so that statement
  567. assigns 5 to the variable "b" is pointing to.  In this case,
  568. that would assign "5" to the variable "a", just as if you had
  569. used this statement:
  570.  
  571.     a = 5;
  572. *Prototype
  573. Functions in C generally consist of two parts:  the prototype
  574. and the function definition.  The prototype tells the compiler
  575. the name of the function, what parameters it uses, and what
  576. type of value it returns.  The function definition tells
  577. the compiler what statements to execute when the function is
  578. called.
  579.  
  580. Here is an example of a function prototype:
  581.  
  582.     int sum(int a);
  583.  
  584. And here is an example of a function definition:
  585.  
  586.     int sum(int a) {
  587.         int sum=0;
  588.         int i;
  589.         for (i=0; i<a; ++i) {
  590.             sum += i;
  591.         }
  592.         return sum;
  593.     }
  594.  
  595. Generally, function prototypes are placed near the beginning
  596. of a program.  That allows the compiler to know about the function
  597. so it can be called before it has seen the actual function itself.  (If
  598. the compiler didn't see the prototype for the function before any calls
  599. to the function, it might not be able to handle the calls properly.)
  600. *Short
  601. The word "short" can be used to change the size of integer variables.  For
  602. example:
  603.  
  604.     int a;
  605.  
  606. This declares a "regular" integer.  This declares a "short" integer:
  607.  
  608.     short int b;
  609.  
  610. A short integer is often shorter than a regular integer, which means it
  611. uses less storage space, but cannot hold as large a value.
  612.  
  613. (Each compiler is allowed to select whatever size it wants, within limits,
  614. for both regular and short integers.  As a result, it is possible that a
  615. short integer will be the same size as a regular integer for any given
  616. compiler.)
  617. *Statement
  618. A C program consists of one or more functions.  Within each function
  619. are a series of "statements".  A "statement" is simply an instruction that
  620. tells the computer to do something.  Here is an example of a function:
  621.  
  622.     void myFunction(void) {
  623.         a = 5;
  624.         b = 6 * a;
  625.     }
  626.  
  627. This function has two statements:  "a = 5;" and "b = 6 * a;".  When the
  628. function is executed, the first statement will be performed, and then the
  629. second statement will be performed.  The end of each statement is marked
  630. with a ";".
  631. *String
  632. A "string" is a series of characters.  In C, strings can be stored
  633. as constants by enclosing them in quotes, like this:
  634.  
  635.     "abcd"
  636.  
  637. This represents the string consisting of 5 characters:  a, b, c, d, and a null
  638. character.  The end of a string is always identified by a null character
  639. in C.  (A "null character" is a character whose numeric value is zero.)
  640.  
  641. Strings are often stored in character arrays in C.  For example:
  642.  
  643.     char a[10] = "abcd";
  644.  
  645. This declares an array of 10 characters, and it assigns the first 5 of those
  646. characters to be a, b, c, d, and null.
  647.  
  648. The standard libraries that are included with most C compilers provide a variety
  649. of functions that can manipulate strings.  For example, here is a call to a
  650. standard function that would copy a new string into the "a" array:
  651.  
  652.     strcpy(a,"different");
  653. *Struct
  654. A "struct" is a type of data in C that consists of other data elements.  For
  655. example, you could combine three integers into a struct like this:
  656.  
  657.     struct date {
  658.         int year;
  659.         int month;
  660.         int day;
  661.     };
  662.  
  663. This example simply declares the layout of a struct, it doesn't create any
  664. variables.  To declare a variable of this struct, you could do something like
  665. this:
  666.  
  667.     struct date a;
  668.  
  669. This declares the variable "a" to be a struct.  You can then work with each
  670. of the individual integers within the struct like this:
  671.  
  672.     a.year = 2010;
  673.     a.month = 10;
  674.     a.day = 10;
  675.  
  676. You can use "a.year" anyplace you would use an integer variable.
  677. *Switch
  678. The "switch" statement in C allows you to write several pieces of code,
  679. and indicate which of those pieces of code should be executed based on a
  680. variable.  For example:
  681.  
  682.     switch (a) {
  683.  
  684.     case 2:
  685.         b = 5;
  686.         break;
  687.  
  688.     case 4:
  689.         b = 12;
  690.         break;
  691.  
  692.     default:
  693.         b = 99;
  694.         break;
  695.     }
  696.  
  697. In this case, one of the three statements ("b=5", "b=12", or "b=99") will be
  698. executed, depending upon the value of variable "a".  If "a" is 2, the first 
  699. statement will be executed; if "a" is 4, the second statement will be
  700. executed; if "a" has any other value, the last statement will be executed.
  701.  
  702. The "switch" statement can use any expression.  For example, this would select which
  703. statement to be executed based on the value of the expression "a+5":
  704.  
  705.     switch (a+5) {
  706.  
  707.     case 2:
  708.         b = 5;
  709.         break;
  710.  
  711.     case 4:
  712.         b = 12;
  713.         break;
  714.  
  715.     default:
  716.         b = 99;
  717.         break;
  718.     }
  719. *Variable
  720. A "variable" is a location in the computer's memory.  Each variable has a
  721. "value", which is the information stored in that location in memory.  It also
  722. has a "name", which is how that location is identified in a program.
  723.  
  724. For example, this statement tells the computer to reserve enough memory
  725. to hold an integer value:
  726.  
  727.     int a;
  728.  
  729. It assigns the name "a" to that location in memory.  You can put information
  730. into that location like this:
  731.  
  732.     a = 5;
  733.  
  734. This would store a "5" in that location in memory.  You can get the information
  735. out of the location by using the name "a" in another statment, like this:
  736.  
  737.     b = a * 2;
  738.  
  739. This statement would retrieve the contents of storage location "a", multiply
  740. it by two, and store the result in the storage location named "b".
  741. *Void
  742. Functions in C often have some data sent to them, and they then send some
  743. data back.  The keyword "void" can be used to indicate either that no
  744. data is being sent to the function, or that no data is being sent back.
  745.  
  746. For example, here is a function:
  747.  
  748.     int sum(float a) {
  749.         int b;
  750.         b = a * 5;
  751.         return b;
  752.     }
  753.  
  754. This function is sent a floating point value, and sends back an integer.  If
  755. you don't want the function to return a value, you can
  756. put the word "void" for the return value, like this:
  757.  
  758.     void sum(float a) {
  759.         int b;
  760.         b = a * 5;
  761.     }
  762.  
  763. If you won't be sending any data to the function, you can use "void" like this:
  764.  
  765.     int sum(void) {
  766.         int b;
  767.         b = 5 * 23;
  768.         return b;
  769.     }
  770. *While
  771. This statement causes a loop to occur.  Here is an example:
  772.  
  773.     while (i < 100) {
  774.         i += 20;
  775.     }
  776.  
  777. In this case, the statement inside the loop ("i += 20") will
  778. be executed over and over until the condition ("i < 100") is 
  779. no longer true.
  780.  
  781. It is important to understand the difference between a "do"
  782. loop and a "while" loop.  Here's an example of a "do" loop:
  783.  
  784.     do {
  785.         i += 20;
  786.     } while (i < 100);
  787.  
  788. This code does *almost* the same thing as the earlier example,
  789. but with one difference:  the second example will execute the
  790. statement inside the loop ("i += 20") at least once, no matter
  791. what value "i" had before the loop began.  The first example
  792. would not execute the interior of the loop even once if "i"
  793. was already greater than 100.
  794. *End
  795.