Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.

Slides:



Advertisements
Similar presentations
Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
Advertisements

C Programming Day 1 based upon Practical C Programming by Steve Oualline CS550 Operating Systems.
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
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)
Guide To UNIX Using Linux Third Edition
1 Chapter Two Introduction to the Programming Language C.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Computer Science 210 Computer Organization Introduction to C.
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 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Gator Engineering 1 Chapter 2 C Fundamentals Copyright © 2008 W. W. Norton & Company. All rights reserved.
C Programming Lecture 4 : Variables , Data Types
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Lecture #5 Introduction to C++
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Lecture 3: Getting Started & Input / Output (I/O) “TRON” Copyright 1982 (Walt Disney Productions)
Introduction to Programming
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
1 Homework Done the reading? –K&R –Glass Chapters 1 and 2 Applied for cs240? (If not, keep at it!) Gotten a UNIX account? (If not, keep at it!)
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
C is a high level language (HLL)
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
BIL 104E Introduction to Scientific and Engineering Computing Lecture 2.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
Lecture 3: Getting Started & Input / Output (I/O)
Introduction to C Topics Compilation Using the gcc Compiler
Last week: We talked about: History of C Compiler for C programming
CSCE 206 Structured Programming in C
The Machine Model Memory
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
Computer Science 210 Computer Organization
Zhang Hongyi CSCI2100B Data Structures Tutorial 3
Introduction to C Language
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Revision Lecture
ICS103 Programming in C Lecture 3: Introduction to C (2)
Introduction to C CSE 2031 Fall /3/ :33 AM.
Getting Started with C.
By: Syed Shahrukh Haider
Computer Science 210 Computer Organization
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Introduction to CS Your First C Programs
פרטים נוספים בסילבוס של הקורס
Govt. Polytechnic,Dhangar
Introduction to C Topics Compilation Using the gcc Compiler
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C EECS May 2019.
C – Programming Language
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Getting Started With Coding
Presentation transcript:

Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost 30 years. A language with many high quality numerical libraries available. Available for nearly all computers and operating systems. Excellent for specialty supercomputers. All the above.

Chapter 1 slides2 Who created C? Brian Kernighan and Dennis Ritchie at AT&T Bell Labs. Simultaneous development with the UNIX (now primarily Linux) operating system. Millions and millions and millions of lines of code have been written in C. C libraries have evolved over time and are generally of very high quality.

Chapter 1 slides3 C compilers Are readily available Some are free: –GNU project, Free Software Foundation Some are everywhere, but cheap –Microsoft Visual, … –Borland … –Metrowerx

Chapter 1 slides4 Structure of a C program Program execution begins in a special function called main. C is a block-structured language. The fundamental unit of source is the statement. Statements are usually terminated by a ; Blocks of code (multiple source code statements) are enclosed in braces { }

Chapter 1 slides5 The vocabulary of C The C programming language has about 63 reserved words. There are reserved punctuation marks: { } [ ] ( ) ; + - = * / are the ones we will use at first Variables must have names. Variables and constants must have types. Syntax (and semantics) matter!

Chapter 1 slides6 A simple example /* This is our first program. */ int main(void) { printf(“Hello, World”); }

Chapter 1 slides7 A simple example /* This is our first program. */ int main(void) Execution starts here { printf(“Hello, World”); }

Chapter 1 slides8 A simple example /* This is our first program. */ int main(void )Execution starts here { printf(“Hello, World”);Here is the type }

Chapter 1 slides9 A simple example /* This is our first program. */ int main(void ) Execution starts here { printf(“Hello, World”);Here is the type } Here is a function

Chapter 1 slides10 A simple example /* This is our first program. */ int main(void ) Execution starts here { printf(“Hello, World”);Here is the type } Here is the function’s argument Here is a function

Chapter 1 slides11 A simple example /* This is our first program. */ int main(void ) Execution starts here { printf(“Hello, World”);Here is the type } Here is the function’s argument Here is a function The argument is a character string enclosed by quotes

Chapter 1 slides12 The program can be improved Use the library function by including the header file stdio.h Comment the program to make is clear what it does and who wrote it.

Chapter 1 slides13 The improved program /* This is a comment for the Hello, World program written by A. B. Cee on 1/5/08. */ #include int main(void) { printf(“Hello, World”); }

Chapter 1 slides14 Note the matching delimiters /* This is a comment for the Hello, World program written by A. B. Cee on 1/5/08. */ #include int main() { printf(“Hello, World”); }

Chapter 1 slides15 Some compilers require more information about main /* This is a comment for the Hello, World program written by A. B. Cee on 1/5/08. */ #include int main( ) { printf(“Hello, World”); }

Chapter 1 slides16 Some compilers require more information about main /* This is a comment for the Hello, World program written by A. B. Cee on 1/5/08. */ #include int main( int argc, char *argv[] ) { printf(“Hello, World”); }

Chapter 1 slides17 What does the #include mean? This is an instruction to the pre-processor. In this example, code for the linkage to the standard I/O functions is included. We will see other pre-processor directives later.

Chapter 1 slides18 What is a compiler? Software to take source code and analyze it for syntax and the language’s semantics. Output of the compiler can be object code, which is machine readable. If the source code has errors, error messages are produced, instead.

Chapter 1 slides19 What happens next? If the compiler accepts the source code as being correct, the linker links the object code with the object code of all functions used. If the linker finds all necessary object code, it loads them together and creates an executable file. If not, error.

Chapter 1 slides20 What if there are errors? Who fixes the errors? The programmer. Once all the errors are fixed, is the program done? No. It must be tested carefully and the output compared to the correct results. How? This iterative process is the heart of the course.

Chapter 1 slides21

Chapter 1 slides22 Elementary Data Types in C int (for variables that consist of a single integer) char (for variables that consist of a single character) float (for floating point numbers) double (for double precision floating point numbers)

Chapter 1 slides23 How is data stored? The primary unit is the byte, or 8 bits. A bit can take only the values 0 or 1.

Chapter 1 slides24 Relative sizes of data types TypeNumber of bytes Short2 char1 int4 unsigned4 long (int)8 float4 double8

Chapter 1 slides25 Compilers need size information int main(void) {int i, j; char c, d; float e, f; double g, h; } How many bytes?

Chapter 1 slides26 Compilers need size information int main(void) {int i, j; char c, d; float e, f; double g, h; } How many bytes?

Chapter 1 slides27 How to read bytes in memory A byte consists of 8 bits, each of which is either 0 or 1. Characters need a special encoding (ASCII is the most common) Ints can be positive or negative Floats also can be positive or negative, and have decimal places

Chapter 1 slides28 How to read bytes in memory A byte consists of 8 bits, each of which is either 0 or 1. Characters need a special encoding (ASCII is the most common) Ints can be positive or negative Floats also can be positive or negative, and have decimal places Can’t tell how what a byte means unless we know the organization (like deciphering a code)

Chapter 1 slides29 Output in C: printf printf prints information according to controls and lists of what is to be printed. The controls are given as strings with specifications for printing The specifications control the output by telling what format to use: –int, char, float, double, etc

Chapter 1 slides30 printf specifications Printing control statements must be enclosed in double quotes. Any reference to the printing of an expression must have a description of how it is to be printed. The percent sign (%) signifies the format of the expression to be printed in a conversion specification; everything between the quotes except conversion specifications or escape sequences will be printed as written.

Chapter 1 slides31 printf specifications, cont. %d means that the expression is to be printed as a base 10 integer %c means that the expression is to be printed as a single character %f means that the expression is to be printed as a floating point number A %lf means that the expression is to be printed as a double precision-floating point number. %s means that the expression is to be printed as a string of characters.

Chapter 1 slides32 printf specifications, cont. %o means that the expression is to be printed as a base 8 (octal) integer %x means that the expression is to be printed as a base 16 (hexadecimal) integer %Lf means that the expression is to be printed as a "long" double-precision floating point number

Chapter 1 slides33 #include int main(void) { int i= 10; char c = 'Y'; float f; float h = ; double d, mint = 6.023E3; printf("%d\n",i); printf("\t\t%c\n",c); printf("\t\t%c\n",'Y'); printf("\t\t\t\t%7.2f\n",f); }

Chapter 1 slides34 Output 10 Y

Chapter 1 slides35 #include int main(void) { float h = ; double d, mint = 6.023E3; printf("\t\t\t\t%7.5f\n",h); printf("\t\t\t\t%7.4f\n", ); printf("\t\t\t\t%7.2f\n",d); printf("\t\t\t\t%7.2f\n",mint, "\t\t\t\t%7.2f\n",6.023E3); }

Chapter 1 slides36 The output

Chapter 1 slides37 Other output functions putchar() putchar('H'); puts() puts("This message was printed using puts");

Chapter 1 slides38 Input A general-purpose function is scanf Similar syntax to printf One additional feature – for technical reasons, an ampersand (&) is needed to read in the value of a variable

Chapter 1 slides39 #include int main(void) { int i; printf("Please enter a positive integer\n"); scanf("%d",&i); printf("%d",i*i); }

Chapter 1 slides40 #include int main(void) { int n,m,p,q; printf("Enter 4 integers, separated by blanks,\n"); printf("tabs, returns, or any combination of these\n"); scanf("%d %d %d %d",&n,&m,&p,&q); printf("%d %d %d %d\n",n,m,p,q); }

Chapter 1 slides41 Another common input function getchar() ch = getchar();

Chapter 1 slides42 Constants #include int main(void) { int i= 10; char c = 'Y'; float h, chicken_hawk; const float x = ; }

Chapter 1 slides43