Getting Started With C Programming PDF
Document Details
Uploaded by ContrastyHeliotrope3305
Purdue Polytechnic
2024
Tawfiq Salem
Tags
Summary
The document provides lecture notes for an introductory course on C programming. The document includes information on the history, components, and life-cycle of a C program, as well as a home assignment.
Full Transcript
BASIC KNOWLEDGE GETTING STARTED WITH C VLAB: CHAPTER 01 © August 22, 2024 by Tawfiq Salem. All rights reserved. This presentation may not be duplicated or transmitted, in part or in whole, without the express w...
BASIC KNOWLEDGE GETTING STARTED WITH C VLAB: CHAPTER 01 © August 22, 2024 by Tawfiq Salem. All rights reserved. This presentation may not be duplicated or transmitted, in part or in whole, without the express written permission of the author. Reminders ‣ No lab this week, labs will start next week ‣ Assignment 01 Available on Brightspace Due: Friday [8/30] at 11:59pm 2 Today’s Objectives ‣ History ‣ Computer Components ‣ A simple C program ‣ Life Cycle of a C program ‣ Home Exercise: Read Chapter 1 on VLab, 1.1, 1.2, 1.3, 1.4 3 History ‣ C is a widely used programming language ‣ “C” was developed in 1978 by Brian Kernighan & Dennis Ritchie at AT&T - Bell Laboratories. ‣ “C” was developed to write the UNIX Operating System. ‣ “C” is a small language. ‣ “C” is an ideal language for writing compilers, operating systems, and program micro controllers. ‣ C is NOT an object-oriented language. ‣ C is the father of many later languages like C++, Java, C# Why do we need to write programs for the computer? I can Make Coffee Why do we need to write programs for the computer? I can run Program I can do anything you tell me to ….. What is programming? CNIT 105 is titled “Introduction to C Programming”. What is programming? ‣ Telling a computer what to do? But every time I click on a button or press a key, I am telling the computer what to do. That’s not quite what we mean by programming. ‣ We mean writing computer programs. Back up a second – what is a “program” outside of computing? - a TV show is called a program - a concert has a program – what is going to happen when, in what order Programming is writing step-by-step procedure telling a computer how to do something. You plan out “step-by-step procedure” in advance for how to solve a problem Then we have the computer execute (follow) those step-by-step procedure -the program. Algorithms “Step-by-step procedure” is a mouthful. We have a name for that: an algorithm. The algorithm can be defined as follows: ‣ A “well-ordered collection of unambiguous and effectively computable operations that, when executed, produces a result and halts in a finite amount of time.” [Schneider and Gersting]. What is computer? COMPUTER: is an electronic machine that follows a set of instructions in order that it may be able to accept and gather data and transform these into information The first computers ‣ The first automatic computers were designed to solve one specific problem, for example, some problem in differential equations. ‣ “The oldest known computer”, the Antikythera mechanism, was built around 100 BCE for calendar and astronomical calculations. It was built in Greece. Babbage’s Difference Engine (Start 1823-1842) “The oldest known computer” (100 BCE) Wikimedia Commons, “The Antikythera mechanism”, to compute values of polynomials posted by user “Marsyas” Computers in 1940s Source: ENIAC computer (U. S. Army Photo / Public domain) 11 Modern computer 12 Transistors 13 Three Major Components of a computer ‣ Hardware: is the tangible part of a computer system. ‣ Software: is the non-tangible part that tells the computer how to do its job. ‣ Users: refer to people who use and operate the computer system, write computer programs, and analyze and design the information system. BASIC PC HARDWARE ‣ HARDWARE is the tangible part of a computer system. Parts of a modern computer Motherboard: Where are all the components or devices are connected directly and indirectly Ref. Electronics Guide for Engineering Parts of a modern computer Central Processing Units : The Central Processing Unit (CPU) processes all information in the computer Parts of a modern computer Central Processing Units : The Central Processing Unit (CPU) processes all information in the computer Parts of a modern computer RAM: the computer’s “working memory” “Random Access Memory” Made up of circuits (each one a word) that each hold one number - Numbers are represented in binary Volatile: information is lost when the power goes off. Fast devices to access (retrieve or write to), in nanoseconds Relatively expensive part of the computer Von Neumann architecture: CPU reads instructions from RAM. Parts of a modern Computer ‣ Secondary storage: hard drives, flash drives, DVDs, … Persistent: data can be stored for years or decades Slow (microseconds or milliseconds: < 1/1000th the speed of RAM) Relatively cheap part of the computer Data and instructions must be transferred from secondary storage to RAM before the CPU can use 20 Basic Units of Measurement ‣ BIT is a unit of information equivalent to the result of a choice between only 2 possible alternatives in the binary number system. ‣ BYTE is a sequence of 8 bits (enough to represent one character of alphanumeric data) processed as a single unit for information. Basic Units of Measurement Bit - A bit is the smallest unit of data in a computer. either 0 or 1. Transistors inside a computer's CPU act like switches, which can be turned on and off by electric charge. Spots of north and south magnetism are interpreted as 0 and 1 by the read/write head on a hard disk. The pitted surface creates different reflections to encode 0s and 1s on a CD. binary number ‣ What is going on mathematically in a base-10 number, using 567 as an example. There are 5 hundreds, and 100 = 10*10 or 102. There are 6 tens, and, 10 = 101. Finally, there are 7 ones, and 1 = 100. So, 567 = 5 * 102 + 6 * 101 + 7 * 100 Similarly, we have 1024 = 1 * 103 + 0 * 102 + 2 * 101 + 4 * 100 ‣ In a binary number, we have only two digits: 0 and 1. To get the decimal value from a base-2 number, we need to evaluate the expanded form of a binary number. For example, (10011)2 =1 * 24 + 0 * 23 + 0 * 22 + 1 * 21 + 1 * 20 = (19)10. Since each byte has eight bits, the range of the values represented by a byte is from (0000 0000)2 to (1111 1111)2, which is from 0 to 255 in a decimal system. 23 Basic Units of Measurement bit - A bit is the smallest unit of data in a computer. either 0 or 1. 8 bits = 1 bytes 1024 bytes =1 kilobyte (K or KB) 1024 KB =1 megabyte (MB) 1024 MB =1 gigabyte (GB) 1024 GB =1 Terabyte (TB) Software ‣ Instructions that tell the computer how to process data into the form you want. ‣ Software and programs are interchangeable. ‣ Two major types: System and Applications Two Kinds of Software 1. System Software enables the application software to interact with the computer hardware. Operating Systems are programs that coordinate computer resources, provide an interface between users and the computer; and run applications. Utilities perform specific tasks related to managing computer resources. Device drivers are specialized programs designed to allow particular input or output devices to communicate with the rest of the computer system. Functions of a System Software ‣ Managing resources (memory, processing, storage, and devices like printer). ‣ Providing user interface ‣ Running applications Two Kinds of Software 2. Applications Software - provides the real functionality of a computer. It help you use your computer to do specific types of work. Basic Applications, widely used in all career areas. Specialized Applications, more narrowly focused on specific disciplines and occupations. Computer Computer System Software Hardware Operating System Processor Linux, Windows, Mac, CPU Android, iOS Applications Software Input devices Keyboard, Mouse Word Doc Presentation Output devices Excel etc Storage Primary, Secondary Our Focus on this Course: Application Software Computer System Softwar Hardware e Operating System Processor Linux, Windows, Mac, CPU Android, iOS Applications Software Input devices Keyboard, Mouse Word Doc Presentation Output devices Excel etc Storage Primary, Secondary A Simple “C” program: #include int main() { printf (“Hello World! \n”); return 0; } Let’s have our first demo 31 Life Cycle of a C program: ‣ Pre-processor Source Code Object File (example.c) Compiler (example.obj) Include Files (stdio.h) Linker Executable File (example.exe) Runtime Library 32 Source Code ‣ Is the computer program written by a programmer. ‣ The source code is saved as a file to the disk. ‣ The extension of the source file for a C program is.c 33 Any Questions? 34 Thank You!