IT REVIEWER – C
Below C Level
       Origin
       -   Developed at AT&T Bell Labs in early 1970’s
       -   Created by Dennis Richie
       -   Product of both the B Programming Language and BCPL
       Characteristics
       -   Programming languages have different levels, depending on how they resemble human
           languages
               1. Low-level Languages
               2. Mid-level Languages
               3. High-level Languages
Low-level Languages                            High-level Languages
-consists of numbers and codes that the        -reads almost like English; all its commands &
microprocessor understands and executes        instructions are English words
EX: Assembly Language                          EX: BCPL
ADVANTAGES:
                       High-level                           Low-level
                                           M
                                           I
                                           D
                                           -             - runs programs faster
                - easier to implement      L          - produces smaller program
                                           E                      size
                                           V
                                           E
                                           L
       Mid-level Language
       -compact program size
       -easy development
       -fast running time
       EX: C
Editing, Compiling, and Running a C Program
(syntax – structure, sematics – meaning) *
GCC – GNU Compiler Collection
 Compiler
                                          - examines each
 - reads the instruction                     instruction           - translates the
     from the code                                                   information
                                            (tells errors)
       computer                        - links the object code   - GCC creates object
        program                                   file                 code file
Development Cycle
   1. Save!
   2. Compile and Link!
   3. Run!
   4. Do it Again!
       1.   Save – saving the source code
       -    Create a source code in a text editor
       -    Save it as a C file using .c as extension
       2.   Compile and Link
       -    Source code to object file
       -    Object file to executable file
       3.   Run
       -    Program runs on a terminal
EX:
1. Save                   world.c
                          Filename: world
                          File extension: .c
2. Compile and Link       gcc -o hello world.c
                          Compiler: gcc
                          Linker: -o               (object file - determines name of executable file)
                          Executable File: hello
                          File: world.c
3. Run                    ./hello                  (runnable in terminal)
                          Executable file: hello
Common Errors
     1. Wrong file extension
     2. Using a forward slash (\) when a blackslash (/) is required
     3. Forget to put on & on arguments, causes SEGMENTATION FAULT
         SEGMENTATION FAULT – lacking argument, parameter, or variable
     4. Missing closing and terminating characters, causes SYNTAX ERROR
         - omitting a semicolon (signifies end of line) or a closing brace
         - omitting quotation character
Basic Parts of a C Program
        #include <stdio.h>
          intmain (){
                 printf (“hello world!\n”);
                 return 0;
          }
          #include – directory
          -    instructs the compiler to include another source file
          <stdio.h> or “stdio.h” – header file (.h)
          - Provide protoype declarations for library functions
              Libraries:
              <stdio.h>
              - standard input output
              <math.h>
              - math operations
              <stdlib.h>
              - standard library
              <string.h>
              - string manipulation
       intmain(){
       }             - main function
       - Curly brackets close body
       - Performs the principal function of a program
       printf (“hello world!\n”);
       return 0;                        - main body (in between curly braces)
       return 0; - terminates program
       \n – new line
Variable Declaration
       Variables
       - Temporary holders of values with a specified data type.
               Data Type
               - size and range of values and operations
       - Do not use numbers as a first character
       - No spaces (use underscore)
       - C is case sensitive!
       EX: number1 V          1number X                number 1 X               number_1 V
Data Types in C
 Data Type                Name                      Format Specifier            Description
 void                     Void                                                  Absence of type
 int                      Integer                   %d or %i                    Whole numbers
 char                     Character                 %c                          Letters on symbols
 float                    Float                     %f                          Floating point numbers
                                                                                (six decimal places)
 double                   Double                    %lf                         Floating point numbers
                                                                                (fifteen decimal places)
       Reserved Words
       - Cannot be declared as variables; cannot be used as variable names.
           EX: return
Comments
     // - ignores a line
     /*       */ - used for multi-line comments
        EX:
              /*
              This is a function in C
              */
              //comment
Input and Output Statement
Printing a Statement
 In Pseudocode                                       In C
 DISPLAY “hello world”                               printf(“hello world”);
Getting an Input
scanf (“%d”, &number);
Built in function: scanf ()
Formal specifier: %d
Variable name: number
& - locates variable in a computer
EX:
printf(“There are %d students in this class.”, number);