Functions Dilshad M. Shahid New York

Slides:



Advertisements
Similar presentations
1 Pointers and Strings Section 5.4, , Lecture 12.
Advertisements

EC-111 Algorithms & Computing Lecture #10 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Review for Final Exam Dilshad M. NYU. In this review Arrays Pointers Structures Java - some basic information.
CSCI 1100/ , 6.2, 6.4 April 12, 15, 17.
An Introduction to Programming with C++ Fifth Edition Chapter 10 Void Functions.
Topic 9A – Arrays as Function Arguments. CISC105 – Topic 9A Arrays as Function Arguments There are two ways to use arrays as function arguments: Use an.
Pointers A pointer is a variable that contains memory address as its value. A variable directly contains a specific value. A pointer contains an address.
Review for midterm exam Dilshad M. Shahid Spring NYU.
FunctionsFunctions Systems Programming. Systems Programming: Functions 2 Functions   Simple Function Example   Function Prototype and Declaration.
Functions Pass by Value Pass by Reference IC 210.
Miscellaneous topicsCS-2301 B-term Miscellaneous Topics CS-2301, System Programming for Non-majors (Slides include materials from The C Programming.
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions Modules: functions and classes Programs use new and “prepackaged” modules –New: programmer-defined.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
1 Functions Modules: functions and classes Programs use new and “prepackaged” modules –New: programmer-defined functions, classes –Prepackaged: from the.
FunctionsFunctions Systems Programming Concepts. Functions   Simple Function Example   Function Prototype and Declaration   Math Library Functions.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 14: Overloading and Templates.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 15: Overloading and Templates.
Data Objects (revisited) Recall that values are stored in data objects, and that each data object holds one value of a particular type. Data objects may.
Chapter 6: User-Defined Functions
C Functions Pepper. Objectives Create functions Function prototypes Parameters – Pass by value or reference – Sending a reference Return values Math functions.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Week 6: Functions - Part 2 BJ Furman 01OCT2012. The Plan for Today Comments on midterm exam (next week in lab!) Review of functions Scope of identifiers.
Lecture 13: Working with Multiple Programmers. Headers Header files: Each standard library has a corresponding header. The function prototype for all.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 5.3Math Library Functions Math library functions –perform.
Dale Roberts CSCI 230 Functions Scope, Parameter Passing, Storage Specifiers Department of Computer and Information Science, School of Science, IUPUI Dale.
Structure Programming Lecture 8 Chapter 5&6 - Function – part I 12 December 2015.
Functions in C CSE 2451 Rong Shi. Functions Why use functions? – Reusability Same operation, different data – Abstraction Only need to know how to call.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
More About Data Types & Functions. General Program Structure #include statements for I/O, etc. #include's for class headers – function prototype statements.
Lecture 5 functions 1 © by Pearson Education, Inc. All Rights Reserved.
ECE 103 Engineering Programming Chapter 31 C Scopes Herbert G. Mayer, PSU CS Status 8/1/2015 Initial content copied verbatim from ECE 103 material developed.
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
1 CSC103: Introduction to Computer and Programming Lecture No 16.
C++ Programming Lecture 12 Functions – Part IV
Functions Dilshad M. Shahid New York
Programming Fundamentals Enumerations and Functions.
Building Programs from Existing Information Solutions for programs often can be developed from previously solved problems. Data requirements and solution.
Lists in Python Lists as Arguments/Parameters. Lists as arguments to functions Just like other data types, lists can be sent to functions as arguments.
Lecture 5 – Function (Part 2) FTMK, UTeM – Sem /2014.
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.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
C++ Functions A bit of review (things we’ve covered so far)
1 This week Basics of functions Stack frames Stack vs. Heap (brief intro) Calling conventions Storage classes vs. scope Library functions Overloading.
1 Functions Part 1 Prototypes Arguments Overloading Return values.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
What Is? function predefined, programmer-defined
-Neelima Singh PGT(CS) KV Sec-3 Rohini
Programmer-Defined Functions, Call-by-Value, Multiple Files Lab 5
Programming Fundamentals Lecture #7 Functions
Function There are two types of Function User Defined Function
Programming Fundamentals Lecture #7 Functions
Deitel- C:How to Program (5ed)
Scope, Parameter Passing, Storage Specifiers
2011/11/10: Lecture 21 CMSC 104, Section 4 Richard Chang
More About Data Types & Functions
Register Variables Declaring a variable as a "register" variable is an advisory to the compiler to keep the normal location of the variable in a register,
Function “Inputs and Outputs”
Function.
1-6 Midterm Review.
Chapter 6 Modular Programming chap6.
Nate Brunelle Today: Functions again, Scope
Function.
C Parameter Passing.
Presentation transcript:

Functions Dilshad M. Shahid New York

Today Header files Call by value vs Call by Reference Examples

Header files Each standard library has a corresponding header file The header file contains: –function prototypes for all the functions in that library –definitions of various data types and constants needed by those functions

Header files Examples These and more in table on page 159 of your text

Header files You can create custom header files Write up a program with all your variables and functions (including prototypes) but leave out the main() ) Name it so that it ends in.h, e.g. stuff.h If you want to use the functions in the.h file, in your primary program (i.e. your.c program) put the.h file as an #include at the top

Header files So for example: Your.h file is called stuff.h Your primary program is first.c In first.c, right after #include, put in #include “stuff.h” <> tells you that the.h file is a standard header “ “ tells you that the.h file is a custom header

Call by value vs Call by Reference These are 2 ways to invoke functions In call by value, when arguments are passed, a copy of the argument’s value is made and passed to the called function Changes to the copy don’t affect the original variable’s value in the caller

Call by value vs Call by Reference If you change the value of a variable inside a function and want the caller of the function, usually main(), to see the new value, you must return it Remember you can only return one value per function The return statement must be the last statement before the closing } of the function

Call by value vs Call by Reference Example on webpage

Call by value vs Call by Reference In call by reference, the caller allows the called function to modify the original variable’s value In C, all calls are call by value However, in C, it is possible to simulate call by reference by using address operators and indirection pointers