welcome to c
play

Welcome to C CSCI 112: Programming in C C is a high-level, - PowerPoint PPT Presentation

Welcome to C CSCI 112: Programming in C C is a high-level, imperative programming language C code maps to machine instructions very efficientlyits What is C? lightweight and has wide applications Originally developed in 10973 at


  1. Welcome to C CSCI 112: Programming in C

  2. – C is a high-level, imperative programming language – C code maps to machine instructions very efficiently—it’s What is C? lightweight and has wide applications – Originally developed in 10973 at Bell labs, used to implement the Unix OS

  3. – There are many languages which are “higher level”—why learn such an old, lower-level language? – Age-- C has 30 years of maturity. It’s well understood. Many resources available. – Lingua Franca —C can be used to express a ay to solve a problem in a way everyone understands Why learn C? – Foundational —The concepts of C show up in most other languages in one form or another – No bell and whistles: learning to work at such a low level will make you a better programmer. You’ll have an understanding of exactly what is happening under the hood, and when you move to a higher- level language like Java, this will help you write faster, more robust code.

  4. – macOS – Windows – Linux The World is – iOS Run By C – SQL databases – Graphics programs – Most of your car

  5. System Architecture CSCI 112: Programming in C

  6. – What is hardware, what is software? – Hardware is equipment used to perform computations – Main memory Hardware & – Secondary storage Software – Central Processing Unit (CPU) – Input/output devices – Software is a list of instructions

  7. What is data? – \Data in memory is composed of bits – 0’s and 1’s representing base 2 numbers – Called binary – Bits make up bytes (8 bits per byte Memory on modern systems) – 1 kilobyte = 1,000 bytes = 8,000 bits – 1 megabyte = 1 million bytes – Examples: Binary Base 10 What’s the largest base-10/decimal number 4 bits can represent? 1 1 10 2 11 3 110 4

  8. Main Memory – Also known as RAM – Memory can be though of as a series of “cells” – Each cell holds data or a program instruction – Stored program concept – Programs must be loaded into the memory Memory of the computer before they can be executed. – Data cannot be manipulated by the computer until it is first stored in memory. – Every cell has an address and contents , called a word – word —a collection of bytes – 32 or 64 bits (4 or 8 bytes) on modern systems – Memory cells are never empty, but their contents are meaningless until initialized (set) by the program.

  9. Secondary Storage – Stores large amounts of data at low cost. Memory – Slower than RAM – Organized into files. – Can store data and programs

  10. – The Central Processing Unit is responsible for coordinating computer operations and performing arithmetic and logic operations on data. – It retrieves an instruction from memory, determines which data it needs, fetches that data from memory, and performs the arithmetic/logic operation on that data. CPU – It then stores the result back into memory – CPU’s are actually made up of several different components, including: – Arithmetic Logic Unit – Registers – The CPU knows only how to read and execute machine code

  11. – Input devices allow data to be entered into memory and accessed by program – Mice – Keyboard – Scanner – Camera Input/Output – Output devices present results of program back to users – Terminal – Graphics – Printers – Programs access input data and write to output devices via main memory.

  12. Which of these hardware components are necessary for a computer to operate?

  13. What is a program? – Set of instructions that tells the computer to do things. – Written in a ‘programming language’ - C is one such language Software – Programming languages range from machine languages (meaningful to the computer) to high-level languages (meaningful to the programmer) – Files that contain code for a program are called 'source files' – Instructions are processed one line at a time in consecutive order.

  14. High Level Algebraic expressions, human-readable Languages Basic mnemonic Assembly instructions, each line Language represents 1 machine code instruction Software A binary string Machine representing one Language instruction to be performed by CPU

  15. C Code x = g + h; Assembly Language LOAD g, $1 LOAD h $2 Software ADD $3, $1, $2 STORE $3, x Machine Language (for ADD instruction) 01001 01011 000000010000001 000100 Don’t worry about understanding the assembly or machine code, I just want you to understand how we go from high-level C code down to machine code.

  16. The Operating System – The OS is the base software, the bridge between the programs we write and the hardware that executes them – It takes care of many low-level tasks: Software – Receives commands – Manages memory and gives our programs access to it – Schedules tasks, i.e. processor time – Collects input – Conveys output – Reads and writes data to storage

  17. Compilation and Linking: From High-Level languages to Machine Code – We need to get our source files (C, in this case) into machine language that our CPU understands – This is called compiling Software – We do this for each file in our program – First checks for syntax errors , halts if it finds any – Outputs object files -–contains machine language instructions in binary format – Next, we need to link these files together – Hooks up references from one file to another – Outputs an executable that we can actually run!

  18. – Specify problem & requirements – Forces you to state the problem clearly and unambiguously, to gain a clear understanding of what is required to find the solution. – Analyze problem Software – Identify: Development – inputs (data you have to work with) – outputs (the desired results) Method – Any additional requirements or constraints on the solution – Determine format in which results are to be displayed – Develop list of problem variables and their relationships – The process of modeling a problem by extracting the essential variables and their relationships is called abstraction.

  19. – Design an algorithm to solve the problem.Step 1: develop a list of steps (called an algorithm) to solve the problem. – Step 2: verify that the algorithm solves the problem as intended. Software – Use top-down design (divide and conquer). List major steps Development (subproblems) that need to be solved. Then, solve each subproblem. Once they are all solved, the original problem will be Method solved. – Can save time by doing a desk check on an algorithm by running it on paper in the way a computer would.

  20. – Implement the algorithm. – Convert each algorithm step into one or more statements in a Software programming language. – Test and verify the completed program Development – Run the program with several different sets of input data. Try edge Method cases like 0, -1, and no input at all. Be creative; the more tests you try, the more likely you are to uncover bugs. – Maintain program and update as necessary

Recommend


More recommend