Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

Chapter 4 Constructors and Destructors. Objectives Constructors – introduction and features The zero-argument constructor Parameterized constructors Creating.
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Introduction to C Programming
1 Storage Duration and Scope –Local and global variables Storage classes –automatic, static, external, register Todays Material.
Spring Semester 2013 Lecture 5
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 7: User-Defined Functions II.
Chapter 7: User-Defined Functions II
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
CS 106 Introduction to Computer Science I 02 / 26 / 2007 Instructor: Michael Eckmann.
Chapter 5 C Functions The best way to develop and maintain a large program is to divide it into several smaller program modules, each of which is more.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
ספטמבר 04Copyright Meir Kalech1 C programming Language Chapter 3: Functions.
FunctionsFunctions Systems Programming. Systems Programming: Functions 2 Functions   Simple Function Example   Function Prototype and Declaration.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Methods of variable creation Global variable –declared very early stage –available at all times from anywhere –created at the start of the program, and.
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions Modules: functions and classes Programs use new and “prepackaged” modules –New: programmer-defined.
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.
C++ for Engineers and Scientists Third Edition
C Functions Programmer-defined functions – Functions written by the programmer to define specific tasks. Functions are invoked by a function call. The.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Chapter 6: Modularity Using Functions. In this chapter, you will learn about: – Function and parameter declarations – Returning a single value – Returning.
MAHENDRAN CHAPTER 6. Session Objectives Explain Type of Functions Discuss category of Functions Declaration & Prototypes Explain User Defined Functions.
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
 2007 Pearson Education, Inc. All rights reserved C Functions.
Chapter 6: User-Defined Functions
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
PASSING VALUE TO A FUNCTION # CALL BY VALUECALL BY VALUE # CALL BY REFERENCECALL BY REFERENCE STORAGE CLASS # AUTOAUTO # EXTERNALEXTERNAL # STATICSTATIC.
Learners Support Publications Classes and Objects.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
CPS120: Introduction to Computer Science Functions.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Built-In and user-Defined functions Software Design Concepts Lecture IV Dr. Sothy Vignarajah.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Dale Roberts CSCI 230 Functions Scope, Parameter Passing, Storage Specifiers Department of Computer and Information Science, School of Science, IUPUI Dale.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Functions in C CSE 2451 Rong Shi. Functions Why use functions? – Reusability Same operation, different data – Abstraction Only need to know how to call.
Lecture 10: Modular Programming (functions) B Burlingame 13 April 2015.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
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.
1 MORE ON MODULAR DESIGN: MODULE COMMUNICATIONS. 2 WHEN A FUNCTION IS INVOKED, MEMORY IS ALLOCATED LOCALLY FOR THE FORMAL PARAMETERS AND THE VALUE OF.
Programming Fundamentals Enumerations and Functions.
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
Building Programs from Existing Information Solutions for programs often can be developed from previously solved problems. Data requirements and solution.
Chapter 7 Modularity Using Functions: Part II. A First Book of ANSI C, Fourth Edition 2 Variable Scope If variables created inside a function are available.
A First Book of ANSI C Fourth Edition
1 Chapter 8 Scope, Lifetime, and More on Functions CS185/09 - Introduction to Programming Caldwell College.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
User-Written Functions
Chapter 7: User-Defined Functions II
CSC113: Computer Programming (Theory = 03, Lab = 01)
Programming Fundamentals Lecture #7 Functions
Chapter 5 - Functions Outline 5.1 Introduction
Functions.
User-Defined Functions
C++ for Engineers and Scientists Second Edition
Chapter 5 - Functions Outline 5.1 Introduction
Scope, Parameter Passing, Storage Specifiers
Classes and Objects.
Chapter 7: User-Defined Functions II
Submitted By : Veenu Saini Lecturer (IT)
Presentation transcript:

Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training

Training C/C++Ecosoftware 2 Objectives o Explain the use of functions o Explain the structure of a function o Explain function declaration and function prototypes o Explain the different types of variables o Explain how to call functions o Call by Value o Call by Reference o Explain the scope rules for a function o Explain functions in multifile programs o Explain Storage classes o Explain function pointers

Training C/C++Ecosoftware 3 Program component in C o Function allow you to modularize. o User reused from function. o Function invoked by a function call o Functions are easy to write and understand o Debugging the program becomes easier as the structure of the program is more apparent, due to its modular form

Training C/C++Ecosoftware 4 The Function Structure  The type_specifier specifies the data type of the value, which the function will return.  A valid function name is to be assigned to identify the function.  Arguments appearing in parentheses are also termed as formal parameters.

Training C/C++Ecosoftware 5 Arguments of a function o The program calculates the square of numbers from 1 to 10 o The data is passed from the main() to the squarer() function o The function works on data using arguments

Training C/C++Ecosoftware 6 Returning form a function o It transfers the control from the function back to the calling program immediately. o Whatever is inside the parentheses following the return statement is returned as a value to the calling program.

Training C/C++Ecosoftware 7 Data Type of a Function o The type_specifier is not written prior to the function squarer(), because squarer() returns an integer type value. o The type_specifier is not compulsory if an integer type of value is returned or if no value is returned o However, to avoid inconsistencies, a data type should be specified

Training C/C++Ecosoftware 8 Invoking a Function o A semicolon is used at the end of the statement when a function is called, but not after the function definition o Parentheses are compulsory after the function name, irrespective of whether the function has arguments or not o Only one value can be returned by a function o The program can have more than one function o The function that calls another function is known as the calling function/routine o The function being called is known as the called function/routine

Training C/C++Ecosoftware 9 Function Declaration  Declaring a function becomes compulsory when the function is being used before its definition  The address() function is called before it is defined  Some C compilers return an error, if the function is not declared before calling  This is sometimes referred to as Implicit declaration

Training C/C++Ecosoftware 10 Function Prototypes o Specifies the data types of the arguments o Any illegal type conversions between the arguments used to call a function and the type definition of its parameters is reported char haveParamater(int x, nt y); char noparam (void);

Training C/C++Ecosoftware 11 Variables o Local Variables  Declared inside a function  Created upon entry into a block and destroyed upon exit from the block o Formal Parameters  Declared in the definition of function as parameters  Act like any local variable inside a function o Properties :  Automatic Storage duration.  Block Scope

Training C/C++Ecosoftware 12 Variables o External Variable  Static storage duration  File scope

Training C/C++Ecosoftware 13 Function Scope rules o Scope Rules - Rules that govern whether one piece of code knows about or has access to another piece of code or data o The code within a function is private or local to that function o Two functions have different scopes o Two Functions are at the same scope level o One function cannot be defined within another function

Training C/C++Ecosoftware 14 Calling The Functions o Call by value o Call by reference

Training C/C++Ecosoftware 15 Calling By Value  In C, by default, all function arguments are passed by value  When arguments are passed to the called function, the values are passed through temporary variables  All manipulations are done on these temporary variables only  The arguments are said to be passed by value when the value of the variable are passed to the called function and any alteration on this value has no effect on the original value of the passed variable

Training C/C++Ecosoftware 16 Call by reference o In call by reference, the function is allowed access to the actual memory location of the argument and therefore can change the value of the arguments of the calling routine o Definition  getstr(char *ptr_str, int *ptr_int); o Call getstr(pstr, &var);

Training C/C++Ecosoftware 17 Nesting Function Calls

Training C/C++Ecosoftware 18 Functions in Multifile Programs o Functions can also be defined as static or external o Static functions are recognized only within the program file and their scope does not extend outside the program file o static fn _type fn_name (argument list); o External function are recognized through all the files of the program  extern fn_type fn_name (argument list);

Training C/C++Ecosoftware 19 Thank You End