What's a Computer? Monitor Disk Main mouse Memory Keyboard Network

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
TDBA66, VT-03 Lecture - Ch. 21 A complete C-program Display Fig. 2.1 and comment on different things such as Preprocessor directives Header files Identifiers.
1 CS 201 Introduction to C (1) Debzani Deb. 2 Outline Overview of C General form of a C program C Language Elements.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
C-1 University of Washington Computer Programming I Lecture 3: Variables, Values, and Types © 2000 UW CSE.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
CISC105 General Computer Science Class 1 – 6/5/2006.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Introduction to Programming
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
9/29/99B-1 CSE / ENGR 142 Programming I Variables, Values, and Types © 1998 UW CSE.
A.Abhari CPS1251 Topic 2: C Overview C Language Elements Variable Declaration and Data Types Statement Execution C Program Layout Formatting Output Interactive.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Introduction to C Programming
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Lecture2.
Bill Tucker Austin Community College COSC 1315
Numbers in ‘C’ Two general categories: Integers Floats
CSCE 206 Structured Programming in C
Chapter 1: Introduction to computers and C++ Programming
Input and Output: I/O Finish reading chapters 1 and 2 of the text
INC 161 , CPE 100 Computer Programming
Chapter 2 - Introduction to C Programming
Revision Lecture
Chapter 2 Overview of C.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Variables, Expressions, and IO
Chapter 2 - Introduction to C Programming
Lecture2.
Compiled and ready to run Memory Stack /*
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Chapter 2 - Introduction to C Programming
CC213 Programming Applications
Chapter 11 Introduction to Programming in C
Chapter 2 - Introduction to C Programming
Introduction to CS Your First C Programs
פרטים נוספים בסילבוס של הקורס
Chapter 2 - Introduction to C Programming
CS150 Introduction to Computer Science 1
Chapter 2 - Introduction to C Programming
Lecture3.
WEEK-2.
Chapter 2 - Introduction to C Programming
University of Washington Computer Programming I
Primitive Types and Expressions
Variables in C Topics Naming Variables Declaring Variables
Introduction to C Programming
Variables and Constants
Getting Started With Coding
Presentation transcript:

What's a Computer? Monitor Disk Main mouse Memory Keyboard Network Central Processing Unit Keyboard mouse Main Memory Network CPU: (stupid) brain of the computer can do very simple tasks VERY FAST add, write in memory... Goal: Perform elaborate tasks by putting together many simple tasks HOW ? 142 B-1

Memory and Data All data used by a program (numbers, names…) is stored in the memory of the computer. Think of memory as a (huge) pile of boxes (called words) 1 2 3 4 5 Each box has a number gives the location Each box always contains a value a succession of 0’s and 1’s (a number in base 2) BUT can be interpreted in many ways by a program 142 B-2

Memory and Data Location 4 contains 0.981 4 0.981 1 2 3 4 0.981 109 ‘c’ 3.1415 Location 4 contains 0.981 Location 2 contains the letter ‘c’ In a program do not use the location number (=address) explicitly: don’t want to say “take the content of box 4” would drive us crazy! 142 B-3

Instead: Use a name to refer to the content of a given box a variable Rule of programming: A variable MUST be declared to indicate the type of the variable (is it a character (letter), an integer, a floating point number…?) 142 B-4

Declaring Variables Many different types: some examples A C language declaration int number_of_children; for integer must end with semi-colon (;) no space in the variable name use underscores (_) have meaningful names (NOT int nc;) An integer can be 1, -46, 236 (NOT 1.5, -2.3) 142 B-5

for a floating point, that is 96.2, -14.9, -7.02e-11... double temperature; for a floating point, that is 96.2, -14.9, -7.02e-11... char middle_initial; for a character, that is an individual keyboard character, e.g. ‘b’, ‘A’, ‘0’, ‘+’ (NOT ‘blue’) 142 B-6

Examples double 4 0.981 int 109 3 2 char ‘c’ int 1 3.1415 double 1 2 3 4 0.981 109 ‘c’ 3.1415 double int char int double 142 B-7

Rules for naming variables Rules for C identifiers _ use letters, numbers, underscore: employee_SSN _ can’t start with a number or underscore: _bad, 1_not_good _can’t be a reserved word of the C language: if, while, double, int _ case sensitive: temperature  Temperature _ length: practically as long as you want (but…) _ meaningful names: account_balance (NOT x22yz) 142 B-8

Storing values into variables Declare a variable gives a name to the content of a memory location We get a box. But how to put something in it? Or better said: How to store the value of a variable in the memory? One way: Use an assignment statement a declaration int number_of_children; number_of_children = 3; an assignment statement (don’t forget ;) A statement tells the CPU to do something. A declaration is NOT a statement. There are many kinds of statements. 142 B-9

The structure of a C program preprocessor directive #include <stdio.h> int main(void) { variables declarations program statements return 0; } beginning of program end of program DON’T WORRY about what is in the boxes Explanations will come BUT the contents of the boxes have to be in every program. 142 B-10

An example of program building Problem: convert distances from miles to kilometers Algorithm: Get the distance in miles Convert the distance to kilometers (multiply by 1.609) Display the distance in kilometers How to write this in C? 142 B-11

contains info about printf and scanf for the compiler #include<stdio.h> int main(void) { double miles; /*distance in miles */ double kms;/*distance in kilometers*/ /* Get the distance in miles. */ printf("Enter the distance in miles: "); scanf("%lf", &miles); /*Convert the distance to kilometers*/ kms = 1.609 * miles; /*Display the distance in kilometers*/ printf("That equals %f Kms.\n",kms); return 0; } declarations print on the screen what is between the quotes read from the keyboard to read a double see later (but don’t forget &) multiplication to print a double to print a linefeed 142 B-12

Compilers, Linkers, etc C O .obj file L .c file M I P N I K L E E R R executable program 010 110 .obj file .c file your program library (ANSI) header (stdio.h) debugger Source code Object code 142 B- 13