\documentstyle{report}

\pagestyle{myheadings}
\def\headlineaux{\sc Math 220/317: Programming II/Data Structures
\hrulefill
}
\markboth{\headlineaux}{\headlineaux}

\setlength{\textwidth}{6.25in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}

\newcommand{\outdate}{15 September, 1995}

\begin{document}
\begin{titlepage}\begin{centerline}{\Huge \framebox{Burt Rosenberg}}
\end{centerline}\end{titlepage}

\section*{C Syntax\hfill{\parbox{3in}
    {\small\sc\begin{flushright} Out: \outdate\end{flushright}}}}

\begin{itemize}
\item {\sc Constants.} 
  \begin{itemize}
  \item {\em Integer} such as \verb$1, 0, 14, 0x0A.$
  \item {\em Characters} such as \verb$'A', 'B', '\0'.$
  \item {\em Strings} such as \verb."Hello World!\n", "A"..
  \end{itemize}
\item {\sc Variables,} such as \verb. u, i, u_and_i_are_variables..
\item {\sc Expressions.} Constants and variables are expressions. So
  are expressions connected together by operators and using
  parentheses to group operators. The operators are:
  \begin{itemize}
  \item {\em Arithmetic:} \verb.+, -, *, /, %. and unary \verb.-.
        meaning ``negative.''
  \item {\em Assignment:} \verb.=, +=, -=, *=, &=, |=, ++, --.
  \item {\em Access:} access an array element, \verb.[ ].,
    access a structure element, \verb$.$ or \verb$->$, call a
    function, \verb.( )., access the target of a pointer, \verb.*..
  \item {\em Logical:} \verb.==, !=, <, <=, >, >=, &&, ||, !.
  \item {\em Bitwise:} \verb.&, |, <<, >>, ~, ^.
  \item {\em Utility:} the cast \verb.( )., the address operator
        \verb.&. and the \verb.sizeof. operator.
  \end{itemize}
  {\bf Examples:} \verb$x+1, (x+1), (1+3), x=((y+z)>2)+1, (*x[100]).field, f(1)$
\item {\sc Statements.}
  \begin{itemize}
  \item Expressions followed by a semicolon are statements, such as
  \verb. x=y+1;.
  \item {\em Compound Statements:} a series of declarations, perhaps none,
  followed by series of statements, perhaps none, all enclosed in a pair
  of curly braces.\\
  {\bf Examples:} \verb. { x=1; y=2; }, {int i; i=1; }, {}, {;}.

  \item The {\em If Statement:} \verb$ if ( Expr ) Statement$\\
  {\bf Examples:} \verb. if (x>y) x=y+1; if ((x+1)==y) { x=1; y=2; }. 

  \item The {\em If-Else Statement:}
       \verb$if ( Expr ) Statement else Statement$\\
    {\bf Examples:}\\
      \verb.   if (x>y) x=y+1; else { x=1; y=2; }.\\
      \verb.   if ((x+1)==y) { x=1; y=2; } else x=y+1;.\\
      \verb.   if (x=(y>1)) x++ ; else y-- ;.\\
      \verb.   if (x==y) { x=2; y=3; } else { x=3; y=2 }.\\
      \verb.   if (x==y) ; else { do_only_me++ }.

  \item The {\em While Statement:} \verb$while ( Expr ) Statement$
      \\{\bf Examples:} \verb$while (a>0) a-- ; while ( ++a<100 ) ;$
  \item The {\em For Statement: }
      \verb$for ( Expr1 ; Expr2 ; Expr3 ) Statement$\\
      {\em Note:} This statement is equivalent to 
      \verb$ Expr1 ; while (Expr2) { Statement Expr3; }$\\
      {\bf Examples:} \verb$for(i=0;i<10;i++) a[i]=0 ;$
  \item The {\em Switch Statement:} 
      \verb$switch (Expr) Compound-Statement$,
      where the Compound Statement generally has case-labeled lines:
      \verb$ case Expr: Statement$, and the special 
      \verb$default: Statment$.\\
      {\bf Example:} 
      \begin{verbatim}
         switch( string[0] )
         {
             case 'y': printf("Yes\n") ;
                       break ;
             case 'n': printf("No\n") ;
                       break ;
             default:  printf("string[0] is neither y nor n\n") ;
         }
      \end{verbatim}
  \item Other statements include the {\em Break:} \verb$break;$,
       the {\em Continue:} \verb$continue;$, the {\em Return} of
       two forms: return with value: \verb$return(Expr);$, return
       without value: \verb$return;$, the {\em Conditional Evaluation:}
       \verb$( Expr1 ) ? Expr2 : Expr3 ;$, and the {\em Null:} \verb$;$.
  \end{itemize}
\item {\sc Declarations.}
  These are allowed as the first elements of a compound statement
  or at the outermost level of the file (outside of all curly
  braces). They are of the form: {\em storage-class type name-list \verb.;.}.
  \begin{itemize}
  \item Storage-class: \verb. extern, static, typedef. are the most
      frequently used.
  \item Types: \verb. char, int and double. are the most frequently
      used, as well as a structure specifier or a typedef name.
      Less frequently used are float, unsigned char, unsigned long,
      and a union specifier.
  \item Name-list: a comma separated list of possibly
      initialized declarators of the following kinds: 
      {\em identifier, pointer, function} or {\em array}.
      Parenthesis are used to nest declarators, forming very complex
      types.
  \begin{itemize}
  \item {\em identifier}: a name.
   \item {\em pointer}: \verb.*. followed by a declarator or name.
   \item {\em function}: a declarator or name followed by \verb.().
   \item {\em array}: a declarator or name followed by 
       \verb.[optional-integer]., where the
       optional integer constant indicates the size of the array.
  \end{itemize}
  \item Structure specifier: we come back to talk about these here
     because they are complicated.
     These are of new main forms 
     \begin{itemize}
     \item To declare new structure type:
     \verb$struct optional-structure-tag { declarations }$
      The declarations are a sequence of declarations exactly as
      described by the section, except that the storage-class
      tags do not apply.
     \item To recall a defined structure type:
          \verb$ stuct structure-tag$.
     \end{itemize}
   \item Typedef: The storage class \verb.typedef. declares a name
     for a new type. Write the declaration as if you were defining
     a variable, however the storage class \verb.typedef. will 
     assign to the variable the resulting type, which can then
     be used in further declarations.
      
 \end{itemize}
  {\bf Examples:}\\
  \verb$   int i ; int i, j; int *pntr_i ; int i, *pntr_i ;$\\
  \verb$   double x[100] ; double y, x[100], *pntr ;$\\
  \verb$   char *array_of_10_pntrs_to_char[10] ;$\\
  \verb$   char (*Pntr_to_an_array_of_10_char)[10] ;$\\
  \verb$   struct { int i, j } a_struct, another_struct ;$\\
  \verb$   struct S { int i ; double x ; } Array_of_S[10], *Pntr_to_S ;$\\
  \verb$   struct S yet_another_S_struct, ten_more_such[10] ;$\\
  \verb$   typedef LITTLE_ARRAY[10]; LITTLE_ARRAY i_am_an_array ;$

\item {\sc Function Definition.} These are allowed only at the
  outermost level of the program file. A function named \verb.main.
  is special: there must be one and only one such function for each
  program.
  The syntax is {\em function-declaration(prototype) function-body}.
  \begin{itemize}
  \item {\em Function Declaration with prototype:}
     Use the declaration syntax to give the name and return
     type of the function, and within the parentheses, give
     a comma separated list of declarations giving the name and
     types of the arguments.
     The storage class is ignored for arguments, and only
     the classes extern and static are generally used for the
     function itself. In the case of functions ``static'' means
     a function private to the current file and ``extern'' means
     a function whose name is exported to other files in a project.
  \item {\em Function Body:} A compound statement.
  \end{itemize}
  {\bf Examples:}
  \begin{verbatim}
     int f(int i) { return(i) ; }
     int g( int a[], int n )
     {
       int j, sum ;
       sum = 0 ;
       for ( j=0;j<n;j++ )  sum+= a[j] ;
       return(sum) ;
     }
    char * h(char * s)
    {
       while (*s!=\'0') 
       {
         if (*s==',') break ;
         s++ ;
       }
       return(s) ;  /* a pointer to a character, not *s! */
    }
  \end{verbatim}
 
\item {\sc Preprocessor.} 
  \begin{itemize}
     \item {\em \#include:} Read in text from the named file. 
        If enclosed in double quotes, the file name is used
        exactly. If enclosed in pointy brackets, the include
        file is looked for in the location of system wide include
        files. The preprocessor is not the compiler --- an ending
        semicolon is not used.\\
        {\bf Examples:}\\
        \verb$#include<stdio.h>$\\
        \verb$#include "myheaderfile.h"$
     \item {\em \#define:} Makes the first word that follows
        an alias for the rest of the line. Macros are also created
        using define.\\
        {\bf Examples:}\\
        \verb$#define PI 3.14159$\\
        \verb$#define TRUE 0==0$\\
    \item {\em Conditional Compilation:}
        These controls are used for making C code that compiles on
        many different platforms, using code pieces that adapt to
        the system's configuration. I mention them here because
        they are useful for ``commenting out'' large blocks of
        code when debugging. In C, comments of the \verb./* */.
        type cannot be nested. Instead, use:
        \begin{verbatim}
        #if 0
             The compiler will skip over
             all of this because what
             follows the #if is value 0.
             The compiler begins again
             after the #endif ...
        #endif
        \end{verbatim}
        
  \end{itemize}

\end{itemize}
\end{document}
