Study Notes #5

IDE – Integrated Development Environment

Algorithm – approach or method used to solve a problem

  • If we are to create a program that tests if a number is odd or even:
    • The statements that solve the problem become the program
    • The method that is used to test if the number is odd or even is the algorithm
    • To write a program, you need to write the instructions necessary to implement the algorithm. These instructions would be express in the statements of a particular computer language, such as Java, C++, Objective-C or C

Program – the statements that solve a problem

  • A computer is a machine that does what was told. A program tells the computer what to do. The algorithm is the process behind a program that tells the computer what to do. A programmer maps, designs, and creates the program.

Computer’s Instruction Set – formed by basic operations

  1. To solve a problem using a computer, you must provide a solution to the problem by sending instructions to the instruction set.
  2. A computer program sends the instructions necessary to solve a specific problem.

Higher Level Programming Languages – make it easier to write programs

Compilers

  • a program that translates the high-level language source code into the detailed set of machine language instructions the computer requires
  • does the high-level thinking and the compiler generates the tedious instructions to the cpu
  • will check that your program has valid syntax for the programming language that you are compiling
  • finds errors and reports them to you and doesn’t produce an executable until you fix them

Writing C Program

  1. Define the program objectives
    • Understand the requirements, you have to get a clear idea of what you want the program to accomplish
  2. Design the program
    • Decide how the program will meet the above requirements
    • What should the user interface be like
    • How should the program be organized
  3. Write the code
    • Start implementation, translate the design in the syntax of C
    • Use a text editor to create what is called a source code file
  4. Compile
    • translate the source into machine code (executable code)
    • consists of detailed instructions to the CPU expressed in a numeric code
  5. Run the program
    • the executable file is a program you can run
  6. Test and Debug
    • debugging – finding and fixing program errors
  7. Maintain and modify the program
    • after the release, have to continue to fix new bugs or add new features
Develop the habit of planning before coding.
Work in small steps and constantly test.

C

  • a general-purpose, imperative computer programming language that supports structured programming
  • uses statements that change a program’s state, focuses on how
  • one of the most widely used programming languages of all time
  • reliable and readable program
  • used on everything
  • preferred language for producing word processing programs, spreadsheets, and compilers
  • popular for programming embedded systems
  • continues to play a strong role in the development of Linux
  • easy to modify and adapt to new models or languages
  • C is a subset of C++ with object-oriented programming tools added

Features

  • produces compact and efficient programs
  • one of the most important programming languages and will continue to be so
  • portable
  • programmer-oriented
  • pointers play a big role in C
    • direct access to memory
    • supports efficient use of pointers

Disadvantages

  • use of pointers is problematic and abused
  • you can make programming errors that are difficult to trace
  • there is opportunity to write obscure code

kernel – the brain of operating system

Four Fundamentals Tasks in the Creation of any C Program

  1. Editing – the process of creating and modifying your C source code
    • source code is inside a file and contains the program instructions you write
    • choose a wise name for your base file name (all source files end in the .c extension)
    • we will use an IDE (code blocks) for this class, but you can use any editor to create your source code
  2. Compiling
    • a compiler converts your source code into machine language and detects and reports errors in your code
    • the input to the compiler is the file you produce during your editing (source file)
    • Two-Stage Process
      1. Preprocessing phase – code may be modified or added to
      2. Actual compilation that generates the object code
    • the standard command to copile your C programs will be cc (or the GNU compiler, which is .gcc)
      • cc -c myprog.c or gcc -c myprog.c
      • if you omit the -c flag, your program will automatically be linked as well
  3. Linking
    • the purpose of the linking phase is to get the program into a final form for execution on the computer
    • linking usually occurs automatically when compiling depending on what system you are on, but, can sometimes be a separate command
    • success fill produce and executable file
      • Windows .exe
      • UNIX/Linux a.out
  4. Executing
syntactic error - expression that has unbalanced parentheses

semantic error - use of a variable that is not defined

Leave a Reply