Today - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Today

Description:

Always defines a function' to perform. Usually the function ... Camelback: use capitals to mark words. itemsOrdered, totalPayment. DO NOT USE $ to start a name ... – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 17
Provided by: ricks6
Category:
Tags: camelback | today

less

Transcript and Presenter's Notes

Title: Today


1
Todays Class
  • Recap of a simple program
  • A history of C
  • The nuts and bolts of compiling programs
  • Overview of Statements and Variables
  • Simple types
  • Printing out text

2
C Program
  • Always in a file
  • Always defines a function to perform
  • Usually the function is named main
  • We compile it to make it work

3
History of C
  • Interpreting expressions (1940s)
  • Sort/Merge Generator
  • A2 Compiler
  • Fortran
  • Algol
  • C

4
Compiling - the mechanics
  • Command Line compiling
  • Should work the same on PCs and Macs
  • You have to compile programs to run them
  • gcc hello.c
  • You simply command the computer to run the
    program
  • hello
  • Hello, world!

5
Compiling and Running
  • What is really happening?
  • How a program executes
  • Computer Languages
  • Interpeting
  • Compiling
  • Running real instructions
  • What it looks like in RAM

6
Sample C Program
  • / R. Smith
  • First program assignment, QMCS 130
  • January 29, 2008
  • /
  • include ltstdio.hgt
  • int main (void)
  • printf("Hello, world\n")
  • return 0

7
Observations
  • Case sensitive match cases exactly
  • Program is worked in order from start to end
  • Sequences are fundamental to computing
  • Curly braces mark nested components
  • Hierarchies are fundamental to computing
  • Learn the patterns of typical programming tasks
  • Setting up the program
  • Doing output

8
Statements and Variables
  • Statements well use
  • Function declarations like main
  • Always followed by a pair of parentheses,
  • and then curly braces
  • Other statements are followed by a
  • Variable declarations
  • Assignment statements
  • Variables
  • Storage cells in your program
  • Each one is like a spreadsheet cell,
  • only dumber

9
Variable Naming
  • Naming Structure
  • First character A-Z, a-z, _ or
  • Remaining same plus digits
  • Style rules
  • Descriptive names
  • Usually start with lowercase letter
  • Camelback use capitals to mark words
  • itemsOrdered, totalPayment
  • DO NOT USE to start a name

10
Syntax is King
  • AC

11
Assignment Statements
  • Variable substitution
  • where we fill one thing in with another

12
Types of variables
  • First use you say the type
  • int integer
  • signed, no decimal part, less than 2G
  • Examples
  • int sampleInt 12
  • sampleInt 25

13
Printing
  • The printf() function
  • Syntax of functions
  • Takes 1 or more arguments or parameters
  • First argument format string
  • A string of characters to print
  • Embedded signals to say what else to print (
    character)
  • Each signal corresponds to a subsequent
    parameter
  • Extra parameters
  • One per format signal
  • i integers
  • c individual characters
  • s strings of characters

14
Sample 1 string declarations
  • char myname Rick

15
Sample 2
  • Dear John Smith,
  • We are pleased, John, that you have agreed to
    represent the Smith family in the upcoming event.
    All members of the Smith family will be thrilled
    with the results. Your name, John, will be
    remembered for generations by other members of
    the Smith family.
  • Sincerely,
  • The Company.

16
Creative Commons License
  • This work is licensed under the Creative Commons
    Attribution-Share Alike 3.0 United States
    License. To view a copy of this license, visit
    http//creativecommons.org/licenses/by-sa/3.0/us/
    or send a letter to Creative Commons, 171 Second
    Street, Suite 300, San Francisco, California,
    94105, USA.
Write a Comment
User Comments (0)
About PowerShow.com