EPSII 59:006 Spring 2004. Introduction to C More Administrative Details The C Programming Language How a computer processes programs Your first C program.

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
Lecture 2 Introduction to C Programming
Introduction to C Programming
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 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++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
Introduction to C Programming
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
Structure of a C program
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.
Software Lesson #1 CS1313 Spring Software Lesson 1 Outline 1.Software Lesson 1 Outline 2.What is Software? A Program? Data? 3.What are Instructions?
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
CS 201 Functions Debzani Deb.
Introduction to C Programming
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
C programming Language and Data Structure For DIT Students.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
Computer Science 210 Computer Organization Introduction to C.
Chapter 3 Getting Started with C++
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
1 Agenda Administration Background Our first C program Working environment Exercise Memory and Variables.
C Programming Lecture 4 : Variables , Data Types
Programming With C.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Week 1 Algorithmization and Programming Languages.
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.
PHYS 2020 Basic C An introduction to writing simple but useful programs in C In these lectures I will take you through the basics of C, but you will need.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
1 A simple C++ program // ======================================================= // File:helloworld.cpp // Author:Vana Doufexi // Date:1/4/2006 // Description:Displays.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
CMSC 104, Lecture 111 Introduction to C Topics l Compilation l Using the gcc Compiler l The Anatomy of a C Program l 104 C Programming Standards and Indentation.
Minimal standard C program int main(void) { return 0 ; }
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
C++ for Engineers and Scientists Second Edition
Week 1 Lecture 2SE1SA51 Introducing C SE1SA5 Sue Walmsley.
 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.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
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.
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.
Computer Science 210 Computer Organization
Chapter 2 Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
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.
Introduction to C Topics Compilation Using the gcc Compiler
Getting Started with C.
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 2 - Introduction to C Programming
Computer Science 210 Computer Organization
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 2 - Introduction to C Programming
Programming Fundamentals Lecture #3 Overview of Computer Programming
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming
Introduction to C Programming
Presentation transcript:

EPSII 59:006 Spring 2004

Introduction to C More Administrative Details The C Programming Language How a computer processes programs Your first C program Anatomy of a C program

More Administrative Details Evening Exams Will try to have T.A.’s in lab by Monday (1245 SC) Accessing Unix systems

Course web page Note: use webCT4.1 Exams: concurrent exams at night Unified HW assignments Grading uniform across all sections.

Introduction to the C Programming Language C is a powerful high-level programming language that also maintains the ability to do some low-level stuff With the power of C comes both freedom and responsibility  The language’s rules allow for many different programming techniques  This freedom can get you into trouble!

Writing C Programs In this course you will learn one consistent approach to writing C programs (and pick up much information common to any way of writing these programs) If you try hard to conform to the guidelines presented, you will be up and running with a minimum of difficulty

How does a computer process a user program?

A simple C program

Compiling, linking, and running Next, compile, link, and run your program: % gcc simple.c –o simple % simple I am a simple computer. My favorite number is 1 because it is first. %

Anatomy of a C Program

Fundamental Aspect of a C Program:  Everything is a function!  Functions are blocks, and curly braces { and } delimit blocks  So, int main(void) { ……..…… return 0; } Is a function Well learn more about functions in a moment

Anatomy of a C Program The main () function  Tells the compiler to start with this function  Calls other functions in your program  Example: int f1(void) { return 1; } int f2(void) { return1; } int main(void) { f1(); f2(); return 0; }

Anatomy of a C Program #include This is actually a pre-processor statement that includes a header file (note the.h extension) which describes the standard I/O library functions (needed for printf() in this program). Anytime you use functions from external libraries you should include a header file to tell the compiler about the function you are using.

Anatomy of a C Program Variables are symbolic names referring to storage in computer memory All variables must be declared in C  variable declaration: int num; All variables must be defined before use:  variable definition: num = 1;

Anatomy of a C Program Variables  Must refer to a specific amount of computer storage (in bytes), but you don’t have to worry about the details – for now you can just use a pre-defined type. Some Predefined Variable Types  int – integer (positive or negative whole number)  char – character variable (holds a code describing a character)  double – double-precision floating point, a real number  float – single-precision floating point number

Anatomy of a C Program Where to Declare Variables  In C, you must declare all variables first in a function (this includes main()) Where to Define Variables  Although you can define (initialize) variables anywhere in a function, you usually do it at the top for readability

Anatomy of a C Program Each of these lines of code are called statements Statements always are terminated with a semicolon ‘;’ Functions can return a value: int f1(void); Or, functions can return nothing: void f1(void);

Anatomy of a C Program Functions also take 0 or more arguments, separated by commas:  Examples: int main (void); /* no arguments */ int f1(int); /* a single integer argument */ int f2(int, int); /* two integer arguments */

Example program: Adding two numbers Let’s say you want to add two numbers: int main(void) { int num1,num2,sum; num1 = 1; num2 = 2; sum = num1 + num2; printf("The sum of %d and %d is %d\n", num1, num2, sum); return 0; }

Writing to the screen Use the printf() function:” #include printf( ” This goes to the screen without a new line ” ); printf( ” This gets a new line\n ” );

Writing to the screen Escape Sequences \nnew line \aalert (rings terminal bell) \ttab \\Prints a backslash \* */ Start of comment End of comment