CSC 253 Lecture 6.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 More Syntax; Working with Objects.
Advertisements

Compilation and Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
MIPS Coding. Exercise 1 4/17/2015week04-3.ppt2 Suppose we have three arrays, A, B, C, all of size 10. Now we want to set C[i] = min(A[i], B[i]) for all.
CSE 303 Lecture 16 Multi-file (larger) programs
Reviews for Exam 1 Chapter 1-4 CSc 212 Data Structures, Sec FG CCNY, Fall 2010.
C++ data types. Structs vs. Classes C++ Classes.
More Miscellaneous Topics CS-2301 B-term More Miscellaneous Topics CS-2301, System Programming for Non-majors (Slides include materials from The.
Week 3 Recap CSE 115 – Fall Java Source Code File Made up of: Package declaration Class definition.
1 10/30/06CS150 Introduction to Computer Science 1 Functions Chapter 3, page 313.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
Functions Lecture 4 – Section 2: 9/21/05 Section 4: 9/22/05.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing & using functions  How to declare them, use them, & trace them  Could write programs.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Computer Science Department Data Structure & Algorithms Lecture 8 Recursion.
1 Lecture04: Function Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Defining New Types Lecture 21 Hartmut Kaiser
Computer Engineering Rabie A. Ramadan Lecture 5.
CCSA 221 Programming in C CHAPTER 15 WORKING WITH LARGER PROGRAMS 1 ALHANOUF ALAMR.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
ENEE150 – 0102 ANDREW GOFFIN Functional Decomposition.
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
G3-1 University of Washington Computer Programming I Structuring Program Files © 2000 UW CSE.
Functions  A Function is a self contained block of one or more statements or a sub program which is designed for a particular task is called functions.
Lecture 2 Functions. Functions in C++ long factorial(int n) The return type is long. That means the function will return a long integer to the calling.
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
First Compilation Rudra Dutta CSC Spring 2007, Section 001.
Function PrototypetMyn1 Function Prototype We can declare a function before we use or define it by means of a function prototype. A function prototype.
Objectives: How to define and call functions. Function declarations and how they differ from function definitions. How arguments are passed to functions.
ECE 103 Engineering Programming Chapter 30 C Functions Herbert G. Mayer, PSU CS Status 8/9/2014 Initial content copied verbatim from ECE 103 material developed.
1 This week Basics of functions Stack frames Stack vs. Heap (brief intro) Calling conventions Storage classes vs. scope Library functions Overloading.
Functions, Scope & File IO C++ Lecture 4 Bhaskar Bhattacharya.
TK1924 Program Design & Problem Solving Session 2011/2012
Andrew(amwallis) Classes!
Week 3-4 Control flow (review) Function definition Program Structures
Introduction to the C programming language
CS1010 Discussion Group 11 Week 4 – Overview of C programming.
Functions Separate Compilation
Functions CIS 40 – Introduction to Programming in Python
Chapter 1-4 CSc 212 Data Structures, Sec AB CCNY, Spring 2012
Programming Fundamentals Lecture #7 Functions
Deitel- C:How to Program (5ed)
Larger Projects, Object Files, Prototyping, Header Files, Make Files
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
CSC 253 Lecture 8.
CSC 253 Lecture 13.
Separate Compilation and Namespaces
CSC 253 Lecture 8.
2011/11/10: Lecture 21 CMSC 104, Section 4 Richard Chang
Elec 2607 Digital Switching Circuits
Name: Rubaisha Rajpoot
CSC 253 Lecture 6.
Separating Definition & Implementation
The C Programming Language
CSC 253 Lecture 7.
Principles of Programming Languages
Bryan Burlingame 13 February 2019
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
Template Functions Lecture 9 Fri, Feb 9, 2007.
CMPE212 – Reminders Quiz 1 marking done. Assignment 2 due next Friday.
CS1100 Computational Engineering
10/6: Lecture Topics C Brainteaser More on Procedure Call
EXP file structure.
8.5 Using Recursive Rules with Sequences
CSC 253 Lecture 15.
Review Lab assignments Homework #3
ENERGY 211 / CME 211 Lecture 23 November 12, 2008.
C++ data types.
Chapter 1-4 CSc 212 Data Structures, Sec FG CCNY, 2009
Recursive Function Prepared by Harprith ICT2102 Introduction to Data Structure.
Introduction to Methods and Interfaces
Presentation transcript:

CSC 253 Lecture 6

Declarations vs. Definitions Why do we separate declarations from definitions? What is the rule for placing declarations and definitions? What is “module-based programming” in C?

Our int_math module Let’s define a file that contains two functions pow(int base, int exp) fact(int n) The first function is essentially the same as we wrote in the 3rd week. Let’s start with the header file.

Our int_math.h What idiom do we need to use at the beginning of the file? Let’s write the rest of the code …

Out int_math.c Let’s check parameters for validity … Let’s code fact() recursively. Suppose we compile int_math.c; what will happen?

Separate Compilation We can compile int_math.c even without writing a main program. We just use the -c switch on our call to gcc This produces an object file that can be used later.

The Main Program Now let’s write the main program … (exercise) We can run the program by listing our source file, along with the precompiled object file. We can also compile both files together …