This document discusses C++ functions. It begins by defining what a function is and describing standard and user-defined functions. It then covers the structure of C++ functions including the function signature, parameters, return values, and body. Examples are provided of defining, declaring, calling and overloading functions. The document also discusses scope of variables, passing data between functions, and inline functions.
This document discusses C++ functions. It defines standard functions that come with C++ and user-defined functions. It explains the structure of a C++ function including the function header and body. It discusses declaring function signatures separately from implementations. Parameters and scopes are also covered. Examples are provided of standard math and character functions as well as user-defined functions. Header files for organizing function declarations and implementation files are demonstrated.
Types of C++ functions:
Standard functions
User-defined functions
C++ function structure
Function signature
Function body
Declaring and Implementing C++ functions
This document discusses C++ functions. It defines a function as a group of statements that is given a name and can be called from within a program. The structure of a C++ function includes a header and body. The header specifies the return type, name, and parameters, while the body contains the code. Functions can use value, reference, and constant reference parameters. Variables within a function can be local or global. Standard library functions are pre-defined in headers like <iostream> and <math.h>. The document provides examples of defining, calling, and using different types of functions and parameters in C++.
This document discusses C++ functions. It begins by defining what a function is and describing standard and user-defined functions. It then covers the structure of C++ functions including the function signature, parameters, return values, and body. Examples are provided of defining, declaring, calling and overloading functions. The document also discusses scope of variables, passing data between functions, and inline functions.
C++ functions presentation by DHEERAJ KATARIADheeraj Kataria
The document discusses C++ functions. It defines what a function is and describes the different types of C++ functions including standard and user-defined functions. It explains the structure of C++ functions including the function header, signature, and body. It provides examples of defining, declaring, implementing and calling functions. It also discusses topics like function parameters, scope of variables, inline functions, and building libraries.
It tells about functions in C++,Types,Use,prototype,declaration,Arguments etc
function with
A function with no parameter and no return value
A function with parameter and no return value
A function with parameter and return value
A function without parameter and return value
Call by value and address
The document discusses C++ functions. It explains that functions allow code to be reused by grouping common operations into reusable blocks of code called functions. Functions have three parts: a prototype that declares the function, a definition that implements it, and calls that execute the function. Functions can take parameters as input and return a value. Grouping common code into well-named functions makes a program more organized and maintainable.
Functions allow programmers to structure C++ programs into modular segments of code to perform individual tasks. There are two types of functions: library functions and user-defined functions. User-defined functions are defined using a return type, function name, and parameters. Functions can be called by value or by reference and can also be inline, recursive, or friend functions.
This document discusses C++ functions. It defines standard functions that come with C++ and user-defined functions. It explains the structure of a C++ function including the function header and body. It discusses declaring function signatures separately from implementations. Parameters and scopes are also covered. Examples are provided of standard math and character functions as well as user-defined functions. Header files for organizing function declarations and implementation files are demonstrated.
Types of C++ functions:
Standard functions
User-defined functions
C++ function structure
Function signature
Function body
Declaring and Implementing C++ functions
This document discusses C++ functions. It defines a function as a group of statements that is given a name and can be called from within a program. The structure of a C++ function includes a header and body. The header specifies the return type, name, and parameters, while the body contains the code. Functions can use value, reference, and constant reference parameters. Variables within a function can be local or global. Standard library functions are pre-defined in headers like <iostream> and <math.h>. The document provides examples of defining, calling, and using different types of functions and parameters in C++.
This document discusses C++ functions. It begins by defining what a function is and describing standard and user-defined functions. It then covers the structure of C++ functions including the function signature, parameters, return values, and body. Examples are provided of defining, declaring, calling and overloading functions. The document also discusses scope of variables, passing data between functions, and inline functions.
C++ functions presentation by DHEERAJ KATARIADheeraj Kataria
The document discusses C++ functions. It defines what a function is and describes the different types of C++ functions including standard and user-defined functions. It explains the structure of C++ functions including the function header, signature, and body. It provides examples of defining, declaring, implementing and calling functions. It also discusses topics like function parameters, scope of variables, inline functions, and building libraries.
It tells about functions in C++,Types,Use,prototype,declaration,Arguments etc
function with
A function with no parameter and no return value
A function with parameter and no return value
A function with parameter and return value
A function without parameter and return value
Call by value and address
The document discusses C++ functions. It explains that functions allow code to be reused by grouping common operations into reusable blocks of code called functions. Functions have three parts: a prototype that declares the function, a definition that implements it, and calls that execute the function. Functions can take parameters as input and return a value. Grouping common code into well-named functions makes a program more organized and maintainable.
Functions allow programmers to structure C++ programs into modular segments of code to perform individual tasks. There are two types of functions: library functions and user-defined functions. User-defined functions are defined using a return type, function name, and parameters. Functions can be called by value or by reference and can also be inline, recursive, or friend functions.
This document provides information on functions in C and C++. It discusses the main components of functions including definition, declaration, prototypes, arguments, return values, scope, and recursion. It also covers function categories, nested functions, default arguments, inline functions, function overloading, and differences between calling functions by value versus reference in C++. Overall, the document serves as a tutorial on functions and their usage in C and C++ programming.
This document discusses functions in C++. It defines functions as modules that divide programs into smaller, more manageable pieces. It covers function prototypes, call by reference, return by reference, inline functions, default arguments, constant arguments, recursion, function overloading, friend and virtual functions, and math library functions. The main points are that every C++ program must have a main function, functions can pass arguments by reference to modify the original variables, and functions allow breaking programs into reusable and modular components.
Functions allow code to be reused by defining formulas that can be called from different parts of a program. Functions take in inputs, perform operations, and return outputs. They are defined outside of the main body with a function prototype, and can be called multiple times from within main or other functions. This document demonstrates how to define a FindMax function that takes in two numbers, compares them, and returns the maximum number. It shows function prototypes, defining the function outside of main, and calling the function from within main to find the maximum of two user-input numbers.
C++ functions require prototypes that specify the return type and parameters. Function overloading allows multiple functions to have the same name but different signatures. Default arguments allow functions to be called without providing trailing arguments. Inline functions expand the function body at the call site for small functions to reduce overhead compared to regular function calls.
1. Inline functions are small functions whose code is inserted at the call site instead of generating a function call. This avoids overhead of function calls but increases code size.
2. Function overloading allows different functions to have the same name but different parameters. The compiler determines which version to call based on argument types.
3. C++ classes allow defining data types that bundle together data members and member functions that can access them. Classes support data hiding and inheritance.
Functions in C++, this presentation will cover the following topics
• Functions
• Functions Basics
• Overloaded functions
o Different numbers of arguments
o Different kinds of arguments
Revision Fucntion overloading
• Inline functions
• Default arguments
The document discusses key concepts in C++ including:
1. The main() function is the entry point of a C++ program and can call other functions defined in the source code.
2. main() returns an int value to the operating system. Functions can also return values and references.
3. Functions help reduce code size, save memory, and improve readability and reusability. Parameters can be passed by value or reference.
4. Inline functions provide faster execution by inserting the function code directly into the calling function. They are best for short functions without loops.
The document discusses functions in C++. It defines functions as modular pieces that divide programs into more manageable components. It describes function components like modules, functions, classes, and function calls. It provides examples of math library functions and how to define, call, and prototype functions. It also covers function parameters, return types, and scope rules for local variables and storage classes.
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
This document discusses parameters in C++. There are two types of parameters: formal parameters defined in a function and actual parameters passed during a function call. C++ supports two ways of passing parameters: call by value where the formal parameter is a copy of the actual value, and call by reference where the formal parameter is an alias to the actual parameter. Call by reference allows a function to modify the original value. While it is more efficient for large data types, it can be ambiguous whether a parameter is intended for input or output.
This document discusses functions in C++. It defines a function as having an output type, name, and arguments within parentheses. Functions can be called by passing arguments to the function name. Functions can also be called by reference by passing the address of a variable. Some important mathematical functions are provided in the C++ math library and their Fortran equivalents are shown.
This document discusses functions in C++. It defines a function as a block of code that performs a specific task and can be reused. The key points made are:
- Functions allow for modular and reusable code. They group statements and give them a name to be called from other parts of a program.
- The document demonstrates simple functions in C++ through examples, including defining, declaring, calling, passing arguments to, and returning values from functions.
- Other function concepts covered include function overloading, recursion, inline functions, default arguments, scope and storage class, and global vs local variables.
The document discusses different types of functions in C++ including:
1) Main functions are mandatory while other programs define additional functions. Functions are declared with a return type, name, and parameters.
2) Functions are defined with a syntax including the return type, name, parameters, and body. Functions can be called within other functions or the main function by passing values.
3) Inline functions have their code placed at the call site at compile time to avoid function call overhead. They are defined using the inline keyword before the return type for small, single line functions.
4) Functions can have default arguments which are values provided in the declaration that are used if not passed to the function. They must
1. The document discusses various concepts related to functions in C++ such as function prototypes, passing arguments by reference, default arguments, inline functions, function overloading, and friend functions.
2. It provides examples to explain concepts like passing arguments by reference allows altering the original variable values, a friend function can access private members of a class, and function overloading allows using the same function name for different tasks based on the argument types.
3. The key benefits of concepts like inline functions, passing by reference, and function overloading are also summarized.
Call by value or call by reference in C++Sachin Yadav
Call by value means passing the value directly to a function. The called function uses the value in a local variable; any changes to it DO NOT affect the source variable. In call by value method, the called function creates its own copies of original values sent to it. Any changes, that are made, occur on the function’s copy of values and are not reflected back to the calling function.
This document discusses various aspects of functions in C++ including function prototypes, definitions, calls, overloading, pointers, callbacks, and templates. It provides examples and explanations of each concept. The key topics covered are:
- Function prototypes declare a function's name, return type, and parameters.
- Definitions implement what a function does through code within curly braces.
- Functions are called by name with appropriate arguments.
- Overloading allows different functions to have the same name based on different parameters.
- Function pointers allow functions to be passed as arguments to other functions.
- Callback functions are functions that are passed as arguments to be called later.
- Templates define functions that operate on different data
Function overloading in C++ allows defining multiple functions with the same name as long as they have different parameters. This enables functions to perform different tasks based on the types of arguments passed. An example demonstrates defining multiple area() functions, one taking a radius and the other taking length and breadth. Inline functions in C++ avoid function call overhead by expanding the function code at the call site instead of jumping to another location. Demonstrated with an inline mul() and div() example.
This document discusses functions in C++. It defines what a function is and explains that functions are the building blocks of C++ programs. Functions allow code to be reused, making programs easier to code, modify and maintain. The document covers function definitions, declarations, calls, parameters, return types, scope, and overloading. It also discusses local and global variables as well as pass by value and pass by reference.
The document contains information about Tarandeep Kaur, including her name, section, and roll number. It then lists and describes various topics related to functions in C++, including definition of functions, function calling, function prototypes, void functions, local vs global variables, function overloading, and recursion. Examples are provided to illustrate function calling, passing arguments, return values, and differences between call by value and call by reference.
The document describes the contents of two disks. Disk 1 contains installation files, class library header and source files, project files, and example programs. Disk 2 contains compiler support libraries, startup code objects, and a compact model object file.
The document summarizes common C functions for character, string, and mathematical operations. It lists functions from the ctype.h, string.h, and math.h header files that check character properties, manipulate strings, and perform basic math.
This document provides information on functions in C and C++. It discusses the main components of functions including definition, declaration, prototypes, arguments, return values, scope, and recursion. It also covers function categories, nested functions, default arguments, inline functions, function overloading, and differences between calling functions by value versus reference in C++. Overall, the document serves as a tutorial on functions and their usage in C and C++ programming.
This document discusses functions in C++. It defines functions as modules that divide programs into smaller, more manageable pieces. It covers function prototypes, call by reference, return by reference, inline functions, default arguments, constant arguments, recursion, function overloading, friend and virtual functions, and math library functions. The main points are that every C++ program must have a main function, functions can pass arguments by reference to modify the original variables, and functions allow breaking programs into reusable and modular components.
Functions allow code to be reused by defining formulas that can be called from different parts of a program. Functions take in inputs, perform operations, and return outputs. They are defined outside of the main body with a function prototype, and can be called multiple times from within main or other functions. This document demonstrates how to define a FindMax function that takes in two numbers, compares them, and returns the maximum number. It shows function prototypes, defining the function outside of main, and calling the function from within main to find the maximum of two user-input numbers.
C++ functions require prototypes that specify the return type and parameters. Function overloading allows multiple functions to have the same name but different signatures. Default arguments allow functions to be called without providing trailing arguments. Inline functions expand the function body at the call site for small functions to reduce overhead compared to regular function calls.
1. Inline functions are small functions whose code is inserted at the call site instead of generating a function call. This avoids overhead of function calls but increases code size.
2. Function overloading allows different functions to have the same name but different parameters. The compiler determines which version to call based on argument types.
3. C++ classes allow defining data types that bundle together data members and member functions that can access them. Classes support data hiding and inheritance.
Functions in C++, this presentation will cover the following topics
• Functions
• Functions Basics
• Overloaded functions
o Different numbers of arguments
o Different kinds of arguments
Revision Fucntion overloading
• Inline functions
• Default arguments
The document discusses key concepts in C++ including:
1. The main() function is the entry point of a C++ program and can call other functions defined in the source code.
2. main() returns an int value to the operating system. Functions can also return values and references.
3. Functions help reduce code size, save memory, and improve readability and reusability. Parameters can be passed by value or reference.
4. Inline functions provide faster execution by inserting the function code directly into the calling function. They are best for short functions without loops.
The document discusses functions in C++. It defines functions as modular pieces that divide programs into more manageable components. It describes function components like modules, functions, classes, and function calls. It provides examples of math library functions and how to define, call, and prototype functions. It also covers function parameters, return types, and scope rules for local variables and storage classes.
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
This document discusses parameters in C++. There are two types of parameters: formal parameters defined in a function and actual parameters passed during a function call. C++ supports two ways of passing parameters: call by value where the formal parameter is a copy of the actual value, and call by reference where the formal parameter is an alias to the actual parameter. Call by reference allows a function to modify the original value. While it is more efficient for large data types, it can be ambiguous whether a parameter is intended for input or output.
This document discusses functions in C++. It defines a function as having an output type, name, and arguments within parentheses. Functions can be called by passing arguments to the function name. Functions can also be called by reference by passing the address of a variable. Some important mathematical functions are provided in the C++ math library and their Fortran equivalents are shown.
This document discusses functions in C++. It defines a function as a block of code that performs a specific task and can be reused. The key points made are:
- Functions allow for modular and reusable code. They group statements and give them a name to be called from other parts of a program.
- The document demonstrates simple functions in C++ through examples, including defining, declaring, calling, passing arguments to, and returning values from functions.
- Other function concepts covered include function overloading, recursion, inline functions, default arguments, scope and storage class, and global vs local variables.
The document discusses different types of functions in C++ including:
1) Main functions are mandatory while other programs define additional functions. Functions are declared with a return type, name, and parameters.
2) Functions are defined with a syntax including the return type, name, parameters, and body. Functions can be called within other functions or the main function by passing values.
3) Inline functions have their code placed at the call site at compile time to avoid function call overhead. They are defined using the inline keyword before the return type for small, single line functions.
4) Functions can have default arguments which are values provided in the declaration that are used if not passed to the function. They must
1. The document discusses various concepts related to functions in C++ such as function prototypes, passing arguments by reference, default arguments, inline functions, function overloading, and friend functions.
2. It provides examples to explain concepts like passing arguments by reference allows altering the original variable values, a friend function can access private members of a class, and function overloading allows using the same function name for different tasks based on the argument types.
3. The key benefits of concepts like inline functions, passing by reference, and function overloading are also summarized.
Call by value or call by reference in C++Sachin Yadav
Call by value means passing the value directly to a function. The called function uses the value in a local variable; any changes to it DO NOT affect the source variable. In call by value method, the called function creates its own copies of original values sent to it. Any changes, that are made, occur on the function’s copy of values and are not reflected back to the calling function.
This document discusses various aspects of functions in C++ including function prototypes, definitions, calls, overloading, pointers, callbacks, and templates. It provides examples and explanations of each concept. The key topics covered are:
- Function prototypes declare a function's name, return type, and parameters.
- Definitions implement what a function does through code within curly braces.
- Functions are called by name with appropriate arguments.
- Overloading allows different functions to have the same name based on different parameters.
- Function pointers allow functions to be passed as arguments to other functions.
- Callback functions are functions that are passed as arguments to be called later.
- Templates define functions that operate on different data
Function overloading in C++ allows defining multiple functions with the same name as long as they have different parameters. This enables functions to perform different tasks based on the types of arguments passed. An example demonstrates defining multiple area() functions, one taking a radius and the other taking length and breadth. Inline functions in C++ avoid function call overhead by expanding the function code at the call site instead of jumping to another location. Demonstrated with an inline mul() and div() example.
This document discusses functions in C++. It defines what a function is and explains that functions are the building blocks of C++ programs. Functions allow code to be reused, making programs easier to code, modify and maintain. The document covers function definitions, declarations, calls, parameters, return types, scope, and overloading. It also discusses local and global variables as well as pass by value and pass by reference.
The document contains information about Tarandeep Kaur, including her name, section, and roll number. It then lists and describes various topics related to functions in C++, including definition of functions, function calling, function prototypes, void functions, local vs global variables, function overloading, and recursion. Examples are provided to illustrate function calling, passing arguments, return values, and differences between call by value and call by reference.
The document describes the contents of two disks. Disk 1 contains installation files, class library header and source files, project files, and example programs. Disk 2 contains compiler support libraries, startup code objects, and a compact model object file.
The document summarizes common C functions for character, string, and mathematical operations. It lists functions from the ctype.h, string.h, and math.h header files that check character properties, manipulate strings, and perform basic math.
Emotional intelligence involves recognizing one's own emotions and the emotions of others, and using this awareness to guide thinking and behavior. It includes five key capacities: knowing one's emotions, managing emotions, motivating oneself, recognizing emotions in others, and handling relationships. Memory allows humans to store, retain, and recall past experiences, and involves three phases - receiving information, retaining it, and recalling it to apply to activities. Creativity is the ability to generate new ideas or solutions and make new connections between existing ideas or concepts, usually leading to original outcomes.
This document summarizes a student project on psychological topics including emotional intelligence, memory, talent, creativity, and intellectual coefficient. The project addressed these challenging but interesting topics. While choosing this topic was difficult due to its complexity, the students were ultimately satisfied with their project.
The C++ Standard Library provides functions for common tasks like math, strings, I/O, and more. It includes header files that replace older C-style headers. Key headers include <iostream> for I/O, <cmath> for math functions, and <cctype> for character functions. Functions cover tasks from calculating sines and cosines to converting cases and checking digit/letter types. The Standard Library makes programming easier by providing these useful and necessary capabilities.
This document summarizes a seminar on writing skills presented at the University of Mysore. It defines writing skills as an important part of communication that allows transmitting messages with clarity to a wider audience than speaking. It discusses various writing techniques like free writing, planning with outlines or mind maps, developing arguments with examples, and making time for writing practice. The conclusion emphasizes that writing skills are foundational to literacy and improved through focused lessons and daily practice, as they are essential for clear communication.
This document discusses Rakuten's new policy requiring employees to be fluent in English. The policy mandates that executive officers who are not fluent in English after two years will be dismissed. The goal is to encourage employees to take English courses in order to have a functional command of the language and to help Rakuten expand globally online where English is the dominant language. However, some worry this policy may cause anxiety for Japanese employees.
The Essential School's Guide to Adaptive LearningLorna Keane
The next generation learning platform, Fishtree, has this week launched a new feature set to accelerate its impact on the EdTech industry. Fishtree, a global leader in education technology, focused on providing the most powerful education solutions, has branded the launch significant in its unique approach to improving the overall teaching and learning experience.
The intelligent feature signifies a key development in learning analytics, as a facilitator in the personalization process. By enabling adaptive instruction, the analytics not only aid in scaling one-to-one instruction and providing insight into student achievement, but in supporting and developing student self-evaluation, collaboration, critical thinking, and independent learning.
Fishtree's Performance Response offers incredible new insights into student learning, further aiding the adaptive learning process, and tracking student progress and performance in the most accurate way imaginable. A teacher can get a real-time view of the performance and challenges of every student and class, while providing individual learning support, at any time, from any device.
"[Fishtree Performance Response] provides a window into the learning process for both teacher and student. It allows teachers and students to see how they are doing, what they are learning, what they are using. Critically, it allows the Fishtree platform to provide that first response or light touch intervention with the teacher retaining full control, transparency and authority within the process," Jim Butler, Fishtree CTO.
The Fishtree system allows assessments to be taken by students on an objective by objective basis. The system guides the student through the process in a very simple and leading manner. Once an objective has been successfully passed, the next objective will appear, allowing the student to advance. If a student fails to pass the score threshold (specified by the teacher), he/she is automatically re-assessed, and provided with personalized resources to help reach the learning objective. The teacher is involved in the entire process with the ability to view the resources each student uses to complete an assignment, and an option to re-assess any number of students at scale, with one click.
Start your FREE trial or contact us for a personalized demo at https://fishtree.com.
This document defines communication and describes the basic elements and types of communication. It discusses verbal and non-verbal communication. It also outlines the communication cycle involving a sender, message, medium, and receiver. Feedback is identified as the final stage. Barriers to effective communication are also defined, including physical, psychological, language/semantic, organizational structure, and cross-cultural barriers.
Header files contain function and variable definitions that are imported into C++ programs using the #include statement. Header files have a ".h" extension and declare functions and define macros. When a function is used in a C++ program, its definition must be imported from the library by including the appropriate header file. Common header files provide input/output operations (iostream.h), console input/output (conio.h), formatted I/O (iomanip.h), strings (string.h), mathematics functions (math.h), general purpose functions like memory management (stdlib.h), and random number generation (stdlib.h).
This document discusses strategies for good medical documentation. It emphasizes making documentation a priority, planning what to document, using standardized templates like SOAP or CHART, including details, times, and ensuring accuracy by proofreading. Good documentation is important for patient care, legal protection, and reflecting professionalism.
This document provides guidance on effective writing skills, including developing good reading strategies, organizing thoughts, and structuring paragraphs and sentences. It discusses features of business writing such as being terse, clear, and to the point. Basic rules of effective writing include getting to the point by being concise, using paragraphs and lists, choosing the right tone, and avoiding errors through proofreading.
The document discusses functions in C++. It covers standard and user-defined functions, value-returning and void functions, formal and actual parameters, and how to define, declare, and call functions. It also discusses scope of identifiers, value vs reference parameters, function overloading, and functions with default parameters.
Type header file in c++ and its functionFrankie Jones
This document lists common C++ header files and standard functions. It provides a brief description of functions in headers like cassert, cctype, cmath, cstdlib, cstring, and others. Functions like assert, isalnum, ceil, atoi, strcat, and cout are described. The document serves as a reference for commonly used C++ functions organized by header file.
C++ arrays allow storing a fixed number of elements of the same type sequentially in memory. Arrays are declared by specifying the element type and number, such as int numbers[100]. Individual elements can then be accessed via their index like numbers[0]. Arrays can be initialized with a list of values or left uninitialized. Elements are accessed using their index and the array name, like n[5] to get the 6th element.
The document discusses functions in C++. It begins by outlining key topics about functions that will be covered, such as function definitions, standard library functions, and function calls. It then provides details on defining and calling functions, including specifying return types, parameters, function prototypes, scope rules, and passing arguments by value or reference. The document also discusses local and global variables, function errors, and the differences between calling functions by value or reference.
- An array is a collection of consecutive memory locations that all have the same name and type. An array allows storing multiple values of the same type using a single name.
- Arrays in C++ must be declared before use, specifying the type, name, and number of elements. Elements are accessed using an index.
- The main advantages of arrays are that they allow storing and processing large numbers of values efficiently using a single name. Arrays also make sorting and searching values easier.
power point presentation on object oriented programming functions conceptsbhargavi804095
The document discusses C++ functions. It covers the following key points in 3 sentences:
Standard functions that are included with C++ like math functions are discussed as well as how to define user-defined functions. User-defined functions are defined with a function header, parameters, and body. Functions can share data through parameters, either by value or by reference, and variables can have local or global scope.
The document discusses C++ functions. It defines what functions are and their uses in breaking down problems into smaller tasks. There are two types of functions: standard functions that are part of the C++ language and user-defined functions. A function has a signature defining its return type and parameters. Functions are declared and defined in two steps - declaration and implementation. Data can be shared between functions through parameters, which come in two varieties: value parameters that copy argument values, and reference parameters that can modify the original argument values.
The document discusses functions in C programming. It defines a function as a block of code that performs a specific task. There are two types of functions: predefined standard library functions and user-defined functions. The key aspects of a function are its declaration, definition, and call. Functions can be used to break a large program into smaller, reusable components. Parameters can be passed to functions by value or by reference. Recursion is when a function calls itself, and is used in algorithms like calculating factorials. Dynamic memory allocation allows programs to request memory at runtime using functions like malloc(), calloc(), realloc(), and free().
The document discusses functions in C programming. It defines what a function is and explains the advantages of using functions, such as avoiding duplicate code and improving reusability. It describes the different parts of a function - declaration, definition, and call. It explains user-defined and standard library functions. It also covers parameter passing techniques (call by value and call by reference), recursion, and dynamic memory allocation using functions like malloc(), calloc(), realloc(), and free().
The document provides an overview of key C++ concepts including:
- C++ is an extension of C that adds object-oriented features like inheritance, polymorphism, encapsulation and abstraction.
- It discusses the differences between C and C++, data types, variables, arrays, strings, functions, and conditionals.
- The document concludes with examples of C++ programs and practice questions.
This document discusses different types of functions in C++, including user-defined functions, library functions, function parameters, return values, function prototypes, and function overloading. It provides examples to illustrate key concepts like defining functions with different parameters and return types, passing arguments to functions, and returning values from functions. Storage classes like local, global, static local and register variables are also briefly covered. The document is an introduction to functions in C++ programming.
The document discusses different types of storage classes in C++ that determine the lifetime and scope of variables:
1. Local variables are defined inside functions and have scope limited to that function. They are destroyed when the function exits.
2. Global variables are defined outside all functions and have scope in the entire program. They are destroyed when the program ends.
3. Static local variables are local variables that retain their value between function calls. Register variables are local variables stored in processor registers for faster access.
4. Thread local storage allows defining variables that are local to each thread and retain their values similar to static variables. The document provides examples to illustrate local, global, and static variables.
C++ is an object-oriented programming language that was created as an extension of C programming language. It was created by Bjarne Stroustrup in 1979 at Bell Labs. Some key differences between C and C++ include C++ supporting object-oriented programming concepts like classes, inheritance and polymorphism, while C is a procedural language. Pointers and references are commonly used in C++ to pass arguments to functions by reference rather than by value. Arrays and functions are also important elements of C++ programs.
C++ is an object-oriented programming language that was created as an extension of C by Bjarne Stroustrup in 1979 at Bell Labs. It supports concepts like inheritance, polymorphism, and encapsulation. C++ is a systems programming language that is commonly used to develop applications that require high performance or require low-level access to hardware. Some key features of C++ include object-oriented programming, functions, arrays, pointers, strings, file handling, and inheritance. C++ allows programmers to write code that is very close to the underlying hardware and has performance advantages over other languages.
The document provides an overview of the C++ programming language. It discusses the history and development of C++, with key points being that C++ was created by Bjarne Stroustrup in 1983 as an extension of C to support object-oriented programming. It then covers some of the main differences between C and C++, uses of C++, advantages and disadvantages, standard libraries, basic C++ structures like data types, variables, operators, functions, arrays, and pointers.
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...bhargavi804095
C++ is the top choice of many programmers for creating powerful and scalable applications. From operating systems to video games, C++ is the proven language for delivering high-performance solutions across a range of industries.
One of the standout features of C++ is its built-in support of streams. C++ makes it easy to channel data in and out of your programs like a pro. Whether you’re pushing data out to cout or pulling it in from cin, C++ streams are the key to keeping your code in the zone.
The document discusses editing, compiling, and executing a simple C++ program. It begins with an overview of basic C++ programming elements and concepts like tokens, data types, arithmetic operators, and precedence. It then provides examples of simple C++ programs that perform arithmetic calculations and output results. The document emphasizes that understanding programming fundamentals like variables, data types, expressions, and control flow is necessary before writing even basic C++ programs.
Here is a potential solution to the problem in C++:
#include <iostream>
using namespace std;
int main() {
int num1, num2, num3;
cout << "Enter three numbers: ";
cin >> num1 >> num2 >> num3;
int total = num1 + num2 + num3;
float average = total / 3.0;
cout << "The numbers entered were: " << num1 << ", " << num2 << ", " << num3 << endl;
cout << "Their average is: " << average;
return 0;
}
Here is a potential solution to the problem in C++:
#include <iostream>
using namespace std;
int main() {
int num1, num2, num3;
cout << "Enter three numbers: ";
cin >> num1 >> num2 >> num3;
int total = num1 + num2 + num3;
float average = total / 3.0;
cout << "The numbers entered were: " << num1 << ", " << num2 << ", " << num3 << endl;
cout << "Their average is: " << average;
return 0;
}
Some key points:
- Use cin to input the 3 numbers from the
The document provides an introduction to algorithms and key concepts related to algorithms such as definition, features, examples, flowcharts, pseudocode. It also discusses different types of programming languages from first to fifth generation. Key points of structured programming approach and introduction to C programming language are explained including data types, variables, constants, input/output functions, operators, type conversion etc.
Orca: Nocode Graphical Editor for Container OrchestrationPedro J. Molina
Tool demo on CEDI/SISTEDES/JISBD2024 at A Coruña, Spain. 2024.06.18
"Orca: Nocode Graphical Editor for Container Orchestration"
by Pedro J. Molina PhD. from Metadev
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...The Third Creative Media
"Navigating Invideo: A Comprehensive Guide" is an essential resource for anyone looking to master Invideo, an AI-powered video creation tool. This guide provides step-by-step instructions, helpful tips, and comparisons with other AI video creators. Whether you're a beginner or an experienced video editor, you'll find valuable insights to enhance your video projects and bring your creative ideas to life.
The Rising Future of CPaaS in the Middle East 2024Yara Milbes
Explore "The Rising Future of CPaaS in the Middle East in 2024" with this comprehensive PPT presentation. Discover how Communication Platforms as a Service (CPaaS) is transforming communication across various sectors in the Middle East.
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...XfilesPro
Wondering how X-Sign gained popularity in a quick time span? This eSign functionality of XfilesPro DocuPrime has many advancements to offer for Salesforce users. Explore them now!
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...kalichargn70th171
Visual testing plays a vital role in ensuring that software products meet the aesthetic requirements specified by clients in functional and non-functional specifications. In today's highly competitive digital landscape, users expect a seamless and visually appealing online experience. Visual testing, also known as automated UI testing or visual regression testing, verifies the accuracy of the visual elements that users interact with.
WWDC 2024 Keynote Review: For CocoaCoders AustinPatrick Weigel
Overview of WWDC 2024 Keynote Address.
Covers: Apple Intelligence, iOS18, macOS Sequoia, iPadOS, watchOS, visionOS, and Apple TV+.
Understandable dialogue on Apple TV+
On-device app controlling AI.
Access to ChatGPT with a guest appearance by Chief Data Thief Sam Altman!
App Locking! iPhone Mirroring! And a Calculator!!
What to do when you have a perfect model for your software but you are constrained by an imperfect business model?
This talk explores the challenges of bringing modelling rigour to the business and strategy levels, and talking to your non-technical counterparts in the process.
The Comprehensive Guide to Validating Audio-Visual Performances.pdfkalichargn70th171
Ensuring the optimal performance of your audio-visual (AV) equipment is crucial for delivering exceptional experiences. AV performance validation is a critical process that verifies the quality and functionality of your AV setup. Whether you're a content creator, a business conducting webinars, or a homeowner creating a home theater, validating your AV performance is essential.
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...Luigi Fugaro
Vector databases are transforming how we handle data, allowing us to search through text, images, and audio by converting them into vectors. Today, we'll dive into the basics of this exciting technology and discuss its potential to revolutionize our next-generation AI applications. We'll examine typical uses for these databases and the essential tools
developers need. Plus, we'll zoom in on the advanced capabilities of vector search and semantic caching in Java, showcasing these through a live demo with Redis libraries. Get ready to see how these powerful tools can change the game!
Consistent toolbox talks are critical for maintaining workplace safety, as they provide regular opportunities to address specific hazards and reinforce safe practices.
These brief, focused sessions ensure that safety is a continual conversation rather than a one-time event, which helps keep safety protocols fresh in employees' minds. Studies have shown that shorter, more frequent training sessions are more effective for retention and behavior change compared to longer, infrequent sessions.
Engaging workers regularly, toolbox talks promote a culture of safety, empower employees to voice concerns, and ultimately reduce the likelihood of accidents and injuries on site.
The traditional method of conducting safety talks with paper documents and lengthy meetings is not only time-consuming but also less effective. Manual tracking of attendance and compliance is prone to errors and inconsistencies, leading to gaps in safety communication and potential non-compliance with OSHA regulations. Switching to a digital solution like Safelyio offers significant advantages.
Safelyio automates the delivery and documentation of safety talks, ensuring consistency and accessibility. The microlearning approach breaks down complex safety protocols into manageable, bite-sized pieces, making it easier for employees to absorb and retain information.
This method minimizes disruptions to work schedules, eliminates the hassle of paperwork, and ensures that all safety communications are tracked and recorded accurately. Ultimately, using a digital platform like Safelyio enhances engagement, compliance, and overall safety performance on site. https://safelyio.com/
A neural network is a machine learning program, or model, that makes decisions in a manner similar to the human brain, by using processes that mimic the way biological neurons work together to identify phenomena, weigh options and arrive at conclusions.
Odoo releases a new update every year. The latest version, Odoo 17, came out in October 2023. It brought many improvements to the user interface and user experience, along with new features in modules like accounting, marketing, manufacturing, websites, and more.
The Odoo 17 update has been a hot topic among startups, mid-sized businesses, large enterprises, and Odoo developers aiming to grow their businesses. Since it is now already the first quarter of 2024, you must have a clear idea of what Odoo 17 entails and what it can offer your business if you are still not aware of it.
This blog covers the features and functionalities. Explore the entire blog and get in touch with expert Odoo ERP consultants to leverage Odoo 17 and its features for your business too.
An Overview of Odoo ERP
Odoo ERP was first released as OpenERP software in February 2005. It is a suite of business applications used for ERP, CRM, eCommerce, websites, and project management. Ten years ago, the Odoo Enterprise edition was launched to help fund the Odoo Community version.
When you compare Odoo Community and Enterprise, the Enterprise edition offers exclusive features like mobile app access, Odoo Studio customisation, Odoo hosting, and unlimited functional support.
Today, Odoo is a well-known name used by companies of all sizes across various industries, including manufacturing, retail, accounting, marketing, healthcare, IT consulting, and R&D.
The latest version, Odoo 17, has been available since October 2023. Key highlights of this update include:
Enhanced user experience with improvements to the command bar, faster backend page loading, and multiple dashboard views.
Instant report generation, credit limit alerts for sales and invoices, separate OCR settings for invoice creation, and an auto-complete feature for forms in the accounting module.
Improved image handling and global attribute changes for mailing lists in email marketing.
A default auto-signature option and a refuse-to-sign option in HR modules.
Options to divide and merge manufacturing orders, track the status of manufacturing orders, and more in the MRP module.
Dark mode in Odoo 17.
Now that the Odoo 17 announcement is official, let’s look at what’s new in Odoo 17!
What is Odoo ERP 17?
Odoo 17 is the latest version of one of the world’s leading open-source enterprise ERPs. This version has come up with significant improvements explained here in this blog. Also, this new version aims to introduce features that enhance time-saving, efficiency, and productivity for users across various organisations.
Odoo 17, released at the Odoo Experience 2023, brought notable improvements to the user interface and added new functionalities with enhancements in performance, accessibility, data analysis, and management, further expanding its reach in the market.
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio, Inc.
Alluxio Webinar
June. 18, 2024
For more Alluxio Events: https://www.alluxio.io/events/
Speaker:
- Jianjian Xie (Staff Software Engineer, Alluxio)
As Trino users increasingly rely on cloud object storage for retrieving data, speed and cloud cost have become major challenges. The separation of compute and storage creates latency challenges when querying datasets; scanning data between storage and compute tiers becomes I/O bound. On the other hand, cloud API costs related to GET/LIST operations and cross-region data transfer add up quickly.
The newly introduced Trino file system cache by Alluxio aims to overcome the above challenges. In this session, Jianjian will dive into Trino data caching strategies, the latest test results, and discuss the multi-level caching architecture. This architecture makes Trino 10x faster for data lakes of any scale, from GB to EB.
What you will learn:
- Challenges relating to the speed and costs of running Trino in the cloud
- The new Trino file system cache feature overview, including the latest development status and test results
- A multi-level cache framework for maximized speed, including Trino file system cache and Alluxio distributed cache
- Real-world cases, including a large online payment firm and a top ridesharing company
- The future roadmap of Trino file system cache and Trino-Alluxio integration
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
C++ functions
1.
2. Agenda
What is a function?
Types of C++ functions:
Standard functions
User-defined functions
C++ function structure
Function signature
Function body
Declaring and
Implementing C++
functions
Sharing data among
functions through
function parameters
Value parameters
Reference parameters
Const reference
parameters
Scope of variables
Local Variables
Global variable
2
3. Functions and subprograms
The Top-down design appeoach is based on dividing the
main problem into smaller tasks which may be divided
into simpler tasks, then implementing each simple task by
a subprogram or a function
A C++ function or a subprogram is simply a chunk of C++
code that has
A descriptive function name, e.g.
computeTaxescomputeTaxes to compute the taxes for an employee
isPrimeisPrime to check whether or not a number is a prime number
A returning value
The computeTaxesomputeTaxes function may return with a double number
representing the amount of taxes
The isPrimeisPrime function may return with a Boolean value (true or false)
3
4. C++ Standard Functions
C++ language is shipped with a lot of functions
which are known as standard functions
These standard functions are groups in different
libraries which can be included in the C++
program, e.g.
Math functions are declared in <math.h> library
Character-manipulation functions are declared in
<ctype.h> library
C++ is shipped with more than 100 standard libraries,
some of them are very popular such as <iostream.h>
and <stdlib.h>, others are very specific to certain
hardware platform, e.g. <limits.h> and <largeInt.h>
4
5. Example of Using
Standard C++ Math Functions
#include <iostream.h>
#include <math.h>
void main()
{
// Getting a double value
double x;
cout << "Please enter a real number: ";
cin >> x;
// Compute the ceiling and the floor of the real number
cout << "The ceil(" << x << ") = " << ceil(x) << endl;
cout << "The floor(" << x << ") = " << floor(x) << endl;
}
5
6. Example of Using
Standard C++ Character Functions
#include <iostream.h> // input/output handling
#include <ctype.h> // character type functions
void main()
{
char ch;
cout << "Enter a character: ";
cin >> ch;
cout << "The toupper(" << ch << ") = " << (char) toupper(ch) << endl;
cout << "The tolower(" << ch << ") = " << (char) tolower(ch) << endl;
if (isdigit(ch))
cout << "'" << ch <<"' is a digit!n";
else
cout << "'" << ch <<"' is NOT a digit!n";
}
6
Explicit casting
7. User-Defined C++ Functions
Although C++ is shipped with a lot of standard
functions, these functions are not enough for all
users, therefore, C++ provides its users with a way
to define their own functions (or user-defined
function)
For example, the <math.h> library does not
include a standard function that allows users to
round a real number to the ith
digits, therefore, we
must declare and implement this function
ourselves
7
8. How to define a C++ Function?
Generally speaking, we define a C++ function in two
steps (preferably but not mandatory)
Step #1 – declare the function signaturefunction signature in either a
header file (.h file) or before the main function of the
program
Step #2 – Implement the function in either an
implementation file (.cpp) or after the main function
8
9. What is The Syntactic Structure of a C++
Function?
A C++ function consists of two parts
The function header, and
The function body
The function header has the following syntax
<return value> <name> (<parameter list>)<return value> <name> (<parameter list>)
The function body is simply a C++ code enclosed
between { }
9
10. Example of User-defined
C++ Function
double computeTax(double income)
{
if (income < 5000.0) return 0.0;
double taxes = 0.07 * (income-5000.0);
return taxes;
}
10
11. Example of User-defined
C++ Function
double computeTax(double income)
{
if (income < 5000.0) return 0.0;
double taxes = 0.07 * (income-5000.0);
return taxes;
}
11
Function
header
12. Example of User-defined
C++ Function
double computeTax(double income)
{
if (income < 5000.0) return 0.0;
double taxes = 0.07 * (income-5000.0);
return taxes;
}
12
Function
header
Function
body
13. Function Signature
The function signature is actually similar to the
function header except in two aspects:
The parameters’ names may not be specified in the
function signature
The function signature must be ended by a semicolon
Example
double computeTaxes(double) ;
13
Unnamed
Parameter
Semicolon
;
14. Why Do We Need Function Signature?
For Information Hiding
If you want to create your own library and share it with
your customers without letting them know the
implementation details, you should declare all the
function signatures in a header (.h) file and distribute
the binary code of the implementation file
For Function Abstraction
By only sharing the function signatures, we have the
liberty to change the implementation details from time
to time to
Improve function performance
make the customers focus on the purpose of the function, not its
implementation
14
15. Example#include <iostream>
#include <string>
using namespace std;
// Function Signature
double getIncome(string);
double computeTaxes(double);
void printTaxes(double);
void main()
{
// Get the income;
double income = getIncome("Please enter the
employee income: ");
// Compute Taxes
double taxes = computeTaxes(income);
// Print employee taxes
printTaxes(taxes);
}
double computeTaxes(double income)
{
if (income<5000) return 0.0;
return 0.07*(income-5000.0);
}
double getIncome(string prompt)
{
cout << prompt;
double income;
cin >> income;
return income;
}
void printTaxes(double taxes)
{
cout << "The taxes is $" << taxes << endl;
}
15
16. Building Your Libraries
It is a good practice to build libraries to be used by
you and your customers
In order to build C++ libraries, you should be familiar
with
How to create header files to store function signatures
How to create implementation files to store function
implementations
How to include the header file to your program to use
your user-defined functions
16
17. C++ Header Files
The C++ header files must have .h extension and
should have the following structure
#ifndef compiler directive
#define compiler directive
May include some other header files
All functions signatures with some comments about
their purposes, their inputs, and outputs
#endif compiler directive
17
18. TaxesRules Header file
#ifndef _TAXES_RULES_
#define _TAXES_RULES_
#include <iostream>
#include <string>
using namespace std;
double getIncome(string);
// purpose -- to get the employee
income
// input -- a string prompt to be
displayed to the user
// output -- a double value
representing the income
double computeTaxes(double);
// purpose -- to compute the taxes for
a given income
// input -- a double value
representing the income
// output -- a double value
representing the taxes
void printTaxes(double);
// purpose -- to display taxes to the
user
// input -- a double value
representing the taxes
// output -- None
#endif
18
20. Main Program File
#include "TaxesRules.h"
void main()
{
// Get the income;
double income =
getIncome("Please enter the employee income: ");
// Compute Taxes
double taxes = computeTaxes(income);
// Print employee taxes
printTaxes(taxes);
}
20
21. Inline Functions
Sometimes, we use the keyword inlineinline to define
user-defined functions
Inline functions are very small functions, generally, one
or two lines of code
Inline functions are very fast functions compared to the
functions declared without the inline keyword
Example
inlineinline double degrees( double radian)
{
return radian * 180.0 / 3.1415;
}
21
22. Example #1Write a function to test if a number is an odd number
inline bool odd (int x)
{
return (x % 2 == 1);
}
22
23. Example #2
Write a function to compute the distance
between two points (x1, y1) and (x2, y2)
Inline double distance (double x1, double y1,
double x2, double y2)
{
return sqrt(pow(x1-x2,2)+pow(y1-y2,2));
}
23
24. Example #3
Write a function to compute n!
int factorial( int n)
{
int product=1;
for (int i=1; i<=n; i++) product *= i;
return product;
}
24
25. Example #4
Function Overloading
Write functions to return with the maximum number of
two numbers
inline int max( int x, int y)
{
if (x>y) return x; else return y;
}
inline double max( double x, double y)
{
if (x>y) return x; else return y;
}
25
An overloaded
function is a
function that is
defined more than
once with different
data types or
different number
of parameters
26. Sharing Data Among
User-Defined Functions
There are two ways to share data among
different functions
Using global variables (very bad practice!)
Passing data through function parameters
Value parameters
Reference parameters
Constant reference parameters
26
27. C++ Variables
A variable is a place in memory that has
A name or identifier (e.g. income, taxes, etc.)
A data type (e.g. int, double, char, etc.)
A size (number of bytes)
A scope (the part of the program code that can use it)
Global variables – all functions can see it and using it
Local variables – only the function that declare local variables
see and use these variables
A life time (the duration of its existence)
Global variables can live as long as the program is executed
Local variables are lived only when the functions that define
these variables are executed
27
28. I. Using Global Variables
#include <iostream.h>
int x = 0;
void f1() { x++; }
void f2() { x+=4; f1(); }
void main()
{
f2();
cout << x << endl;
}
28
29. I. Using Global Variables
#include <iostream.h>
int x = 0;
void f1() { x++; }
void f2() { x+=4; f1(); }
void main()
{
f2();
cout << x << endl;
}
29
x 0
30. I. Using Global Variables
#include <iostream.h>
int x = 0;
void f1() { x++; }
void f2() { x+=4; f1(); }
void main()
{
f2();
cout << x << endl;
}
30
x 0
void main()void main()
{{
f2();f2();
cout << x << endl ;cout << x << endl ;
}}
1
31. I. Using Global Variables
#include <iostream.h>
int x = 0;
void f1() { x++; }
void f2() { x+=4; f1(); }
void main()
{
f2();
cout << x << endl;
}
31
x 0
void main()void main()
{{
f2();f2();
cout << x << endl ;cout << x << endl ;
}}
1
void f2()void f2()
{{
x += 4;x += 4;
f1();f1();
}}
2
4
32. I. Using Global Variables
#include <iostream.h>
int x = 0;
void f1() { x++; }
void f2() { x+=4; f1(); }
void main()
{
f2();
cout << x << endl;
}
32
45x
void main()void main()
{{
f2();f2();
cout << x << endl ;cout << x << endl ;
}}
1
void f2()void f2()
{{
x += 4;x += 4;
f1();f1();
}}
3
void f1()void f1()
{{
x++;x++;
}}
4
33. I. Using Global Variables
#include <iostream.h>
int x = 0;
void f1() { x++; }
void f2() { x+=4; f1(); }
void main()
{
f2();
cout << x << endl;
}
33
45x
void main()void main()
{{
f2();f2();
cout << x << endl;cout << x << endl;
}}
1
void f2()void f2()
{{
x += 4;x += 4;
f1();f1();
}}
3
void f1()void f1()
{{
x++;x++;
}}5
34. I. Using Global Variables
#include <iostream.h>
int x = 0;
void f1() { x++; }
void f2() { x+=4; f1(); }
void main()
{
f2();
cout << x << endl;
}
34
45x
void main()void main()
{{
f2();f2();
cout << x << endl;cout << x << endl;
}}
1
void f2()void f2()
{{
x += 4;x += 4;
f1();f1();
}}6
35. I. Using Global Variables
#include <iostream.h>
int x = 0;
void f1() { x++; }
void f2() { x+=4; f1(); }
void main()
{
f2();
cout << x << endl;
}
35
45x
void main()void main()
{{
f2();f2();
cout << x << endl;cout << x << endl;
}}
7
36. I. Using Global Variables
#include <iostream.h>
int x = 0;
void f1() { x++; }
void f2() { x+=4; f1(); }
void main()
{
f2();
cout << x << endl;
}
36
45x
void main()void main()
{{
f2();f2();
cout << x << endl;cout << x << endl;
}}8
37. I. Using Global Variables
#include <iostream.h>
int x = 0;
void f1() { x++; }
void f2() { x+=4; f1(); }
void main()
{
f2();
cout << x << endl;
}
37
38. What Happens When We Use Inline
Keyword?
#include <iostream.h>
int x = 0;
InlineInline void f1() { x++; }
InlineInline void f2() { x+=4; f1();}
void main()
{
f2();
cout << x << endl;
}
38
39. What Happens When We Use Inline
Keyword?
#include <iostream.h>
int x = 0;
InlineInline void f1() { x++; }
InlineInline void f2() { x+=4; f1();}
void main()
{
f2();
cout << x << endl;
}
39
0x
void main()void main()
{{
x+=4;x+=4;
x++;x++;
cout << x << endl;cout << x << endl;
}}
1
The inline keyword
instructs the compiler
to replace the function
call with the function
body!
40. What Happens When We Use Inline
Keyword?
#include <iostream.h>
int x = 0;
InlineInline void f1() { x++; }
InlineInline void f2() { x+=4; f1();}
void main()
{
f2();
cout << x << endl;
}
40
4x
void main()void main()
{{
x+=4;x+=4;
x++;x++;
cout << x << endl;cout << x << endl;
}}
2
41. What Happens When We Use Inline
Keyword?
#include <iostream.h>
int x = 0;
InlineInline void f1() { x++; }
InlineInline void f2() { x+=4; f1();}
void main()
{
f2();
cout << x << endl;
}
41
5x
void main()void main()
{{
x+=4;x+=4;
x++;x++;
cout << x << endl;cout << x << endl;
}}
3
42. What Happens When We Use Inline
Keyword?
#include <iostream.h>
int x = 0;
InlineInline void f1() { x++; }
InlineInline void f2() { x+=4; f1();}
void main()
{
f2();
cout << x << endl;
}
42
5x
void main()void main()
{{
x+=4;x+=4;
x++;x++;
cout << x << endl;cout << x << endl;
}}4
43. What Happens When We Use Inline
Keyword?
#include <iostream.h>
int x = 0;
InlineInline void f1() { x++; }
InlineInline void f2() { x+=4; f1();}
void main()
{
f2();
cout << x << endl;
}
43
44. What is Bad About Using
Global Vairables?
Not safe!
If two or more programmers are working together in a
program, one of them may change the value stored in
the global variable without telling the others who may
depend in their calculation on the old stored value!
Against The Principle of Information Hiding!
Exposing the global variables to all functions is against
the principle of information hiding since this gives all
functions the freedom to change the values stored in
the global variables at any time (unsafe!)
44
45. Local Variables
Local variables are declared inside the function
body and exist as long as the function is running
and destroyed when the function exit
You have to initialize the local variable before
using it
If a function defines a local variable and there was
a global variable with the same name, the
function uses its local variable instead of using the
global variable
45
46. Example of Defining and Using Global
and Local Variables#include <iostream.h>
int x; // Global variable// Global variable
Void fun(); // function signature// function signature
void main()
{
x = 4;
fun();
cout << x << endl;
}
void fun()
{
int x = 10; // Local variable// Local variable
cout << x << endl;
}
46
47. Example of Defining and Using Global
and Local Variables#include <iostream.h>
int x; // Global variable// Global variable
Void fun(); // function signature// function signature
void main()
{
x = 4;
fun();
cout << x << endl;
}
void fun()
{
int x = 10; // Local variable// Local variable
cout << x << endl;
}
47
x 0
Global variables are
automatically initialized to 0
48. Example of Defining and Using Global
and Local Variables#include <iostream.h>
int x; // Global variable// Global variable
Void fun(); // function signature// function signature
void main()
{
x = 4;
fun();
cout << x << endl;
}
void fun()
{
int x = 10; // Local variable// Local variable
cout << x << endl;
}
48
x 0
void main()void main()
{{
x = 4;x = 4;
fun();fun();
cout << x << endl;cout << x << endl;
}}
1
49. Example of Defining and Using Global
and Local Variables#include <iostream.h>
int x; // Global variable// Global variable
Void fun(); // function signature// function signature
void main()
{
x = 4;
fun();
cout << x << endl;
}
void fun()
{
int x = 10; // Local variable// Local variable
cout << x << endl;
}
49
x 4
void main()void main()
{{
x = 4;x = 4;
fun();fun();
cout << x << endl;cout << x << endl;
}}
2
void fun()void fun()
{{
int x = 10;int x = 10;
cout << x << endl;cout << x << endl;
}}
x ????
3
50. Example of Defining and Using Global
and Local Variables#include <iostream.h>
int x; // Global variable// Global variable
Void fun(); // function signature// function signature
void main()
{
x = 4;
fun();
cout << x << endl;
}
void fun()
{
int x = 10; // Local variable// Local variable
cout << x << endl;
}
50
x 4
void main()void main()
{{
x = 4;x = 4;
fun();fun();
cout << x << endl;cout << x << endl;
}}
2
void fun()void fun()
{{
int x = 10;int x = 10;
cout << x << endl;cout << x << endl;
}}
x 10
3
51. Example of Defining and Using Global
and Local Variables
#include <iostream.h>
int x; // Global variable// Global variable
Void fun(); // function signature// function signature
void main()
{
x = 4;
fun();
cout << x << endl;
}
void fun()
{
int x = 10; // Local variable// Local variable
cout << x << endl;
}
51
x 4
void main()void main()
{{
x = 4;x = 4;
fun();fun();
cout << x << endl;cout << x << endl;
}}
2
void fun()void fun()
{{
int x = 10;int x = 10;
cout << x << endl;cout << x << endl;
}}
x 10
4
52. Example of Defining and Using Global
and Local Variables
#include <iostream.h>
int x; // Global variable// Global variable
Void fun(); // function signature// function signature
void main()
{
x = 4;
fun();
cout << x << endl;
}
void fun()
{
int x = 10; // Local variable// Local variable
cout << x << endl;
}
52
x 4
void main()void main()
{{
x = 4;x = 4;
fun();fun();
cout << x << endl;cout << x << endl;
}}
2
void fun()void fun()
{{
int x = 10;int x = 10;
cout << x << endl;cout << x << endl;
}}
x 10
5
53. Example of Defining and Using Global
and Local Variables
#include <iostream.h>
int x; // Global variable// Global variable
Void fun(); // function signature// function signature
void main()
{
x = 4;
fun();
cout << x << endl;
}
void fun()
{
int x = 10; // Local variable// Local variable
cout << x << endl;
}
53
x 4
void main()void main()
{{
x = 4;x = 4;
fun();fun();
cout << x << endl;cout << x << endl;
}}
6
54. Example of Defining and Using Global
and Local Variables
#include <iostream.h>
int x; // Global variable// Global variable
Void fun(); // function signature// function signature
void main()
{
x = 4;
fun();
cout << x << endl;
}
void fun()
{
int x = 10; // Local variable// Local variable
cout << x << endl;
}
54
x 4
void main()void main()
{{
x = 4;x = 4;
fun();fun();
cout << x << endl;cout << x << endl;
}}7
55. II. Using ParametersFunction Parameters come in three flavors:
Value parametersValue parameters – which copy the values of the
function arguments
Reference parametersReference parameters – which refer to the function
arguments by other local names and have the ability to
change the values of the referenced arguments
Constant reference parametersConstant reference parameters – similar to the reference
parameters but cannot change the values of the
referenced arguments
55
56. Value ParametersThis is what we use to declare in the function signature or
function header, e.g.
int max (int x, int y);
Here, parameters x and y are value parameters
When you call the max function as max(4, 7)max(4, 7), the values 4 and 7 are
copied to x and y respectively
When you call the max function as max (a, b),max (a, b), where a=40 and b=10,
the values 40 and 10 are copied to x and y respectively
When you call the max function as max( a+b, b/2),max( a+b, b/2), the values 50 and
5 are copies to x and y respectively
Once the value parameters accepted copies of the
corresponding arguments data, they act as local variables!
56
57. Example of Using Value Parameters and
Global Variables#include <iostream.h>
int x; // Global variable// Global variable
void fun(int x)
{
cout << x << endl;
x=x+5;
}
void main()
{
x = 4;
fun(x/2+1);
cout << x << endl;
}
57
x 0
void main()void main()
{{
x = 4;x = 4;
fun(x/2+1);fun(x/2+1);
cout << x << endl;cout << x << endl;
}}
1
58. Example of Using Value Parameters and
Global Variables
#include <iostream.h>
int x; // Global variable// Global variable
void fun(int x)
{
cout << x << endl;
x=x+5;
}
void main()
{
x = 4;
fun(x/2+1);
cout << x << endl;
}
58
x 4
void main()void main()
{{
x = 4;x = 4;
fun(x/2+1);fun(x/2+1);
cout << x << endl;cout << x << endl;
}}
2
void fun(int x )void fun(int x )
{{
cout << x << endl;cout << x << endl;
x=x+5;x=x+5;
}}
3
3
59. Example of Using Value Parameters and
Global Variables
#include <iostream.h>
int x; // Global variable// Global variable
void fun(int x)
{
cout << x << endl;
x=x+5;
}
void main()
{
x = 4;
fun(x/2+1);
cout << x << endl;
}
59
x 4
void main()void main()
{{
x = 4;x = 4;
fun(x/2+1);fun(x/2+1);
cout << x << endl;cout << x << endl;
}}
2
void fun(int x )void fun(int x )
{{
cout << x << endl;cout << x << endl;
x=x+5;x=x+5;
}}
3
4
8
60. Example of Using Value Parameters and
Global Variables
#include <iostream.h>
int x; // Global variable// Global variable
void fun(int x)
{
cout << x << endl;
x=x+5;
}
void main()
{
x = 4;
fun(x/2+1);
cout << x << endl;
}
60
x 4
void main()void main()
{{
x = 4;x = 4;
fun(x/2+1);fun(x/2+1);
cout << x << endl;cout << x << endl;
}}
2
void fun(int x )void fun(int x )
{{
cout << x << endl;cout << x << endl;
x=x+5;x=x+5;
}}
38
5
61. Example of Using Value Parameters and
Global Variables
#include <iostream.h>
int x; // Global variable// Global variable
void fun(int x)
{
cout << x << endl;
x=x+5;
}
void main()
{
x = 4;
fun(x/2+1);
cout << x << endl;
}
61
x 4
void main()void main()
{{
x = 4;x = 4;
fun(x/2+1);fun(x/2+1);
cout << x << endl;cout << x << endl;
}}
6
62. Example of Using Value Parameters and
Global Variables
#include <iostream.h>
int x; // Global variable// Global variable
void fun(int x)
{
cout << x << endl;
x=x+5;
}
void main()
{
x = 4;
fun(x/2+1);
cout << x << endl;
}
62
x 4
void main()void main()
{{
x = 4;x = 4;
fun(x/2+1);fun(x/2+1);
cout << x << endl;cout << x << endl;
}}7
63. Reference Parameters
As we saw in the last example, any changes in the
value parameters don’t affect the original function
arguments
Sometimes, we want to change the values of the
original function arguments or return with more
than one value from the function, in this case we
use reference parameters
A reference parameter is just another name to the
original argument variable
We define a reference parameter by adding the & in
front of the parameter name, e.g.
double update (double && x);
63
64. Example of Reference Parameters
#include <iostream.h>
void fun(int &y)
{
cout << y << endl;
y=y+5;
}
void main()
{
int x = 4; // Local variable// Local variable
fun(x);
cout << x << endl;
}
64
void main()void main()
{{
int x = 4;int x = 4;
fun(x);fun(x);
cout << x << endl;cout << x << endl;
}}
1 x? x4
65. Example of Reference Parameters
#include <iostream.h>
void fun(int &y)
{
cout << y << endl;
y=y+5;
}
void main()
{
int x = 4; // Local variable
fun(x);
cout << x << endl;
}
65
void main()void main()
{{
int x = 4;int x = 4;
fun(x);fun(x);
cout << x << endl;cout << x << endl;
}}
2
x? x4
void fun( int & y )void fun( int & y )
{{
cout<<y<<endl;cout<<y<<endl;
y=y+5;y=y+5;
}}
3
66. Example of Reference Parameters
#include <iostream.h>
void fun(int &y)
{
cout << y << endl;
y=y+5;
}
void main()
{
int x = 4; // Local variable
fun(x);
cout << x << endl;
}
66
void main()void main()
{{
int x = 4;int x = 4;
fun(x);fun(x);
cout << x << endl;cout << x << endl;
}}
2
x? x4
void fun( int & y )void fun( int & y )
{{
cout<<y<<endl;cout<<y<<endl;
y=y+5;y=y+5;
}}
4 9
67. Example of Reference Parameters
#include <iostream.h>
void fun(int &y)
{
cout << y << endl;
y=y+5;
}
void main()
{
int x = 4; // Local variable
fun(x);
cout << x << endl;
}
67
void main()void main()
{{
int x = 4;int x = 4;
fun(x);fun(x);
cout << x << endl;cout << x << endl;
}}
2
x? x9
void fun( int & y )void fun( int & y )
{{
cout<<y<<endl;cout<<y<<endl;
y=y+5;y=y+5;
}}5
68. Example of Reference Parameters
#include <iostream.h>
void fun(int &y)
{
cout << y << endl;
y=y+5;
}
void main()
{
int x = 4; // Local variable
fun(x);
cout << x << endl;
}
68
void main()void main()
{{
int x = 4;int x = 4;
fun(x);fun(x);
cout << x << endl;cout << x << endl;
}}
6
x? x9
69. Example of Reference Parameters
#include <iostream.h>
void fun(int &y)
{
cout << y << endl;
y=y+5;
}
void main()
{
int x = 4; // Local variable
fun(x);
cout << x << endl;
}
69
void main()void main()
{{
int x = 4;int x = 4;
fun(x);fun(x);
cout << x << endl;cout << x << endl;
}}
x? x9
7
70. Constant Reference ParametersConstant reference parameters are used under the
following two conditions:
The passed data are so big and you want to save time
and computer memory
The passed data will not be changed or updated in the
function body
For example
void report (constconst string && prompt);
The only valid arguments accepted by reference
parameters and constant reference parameters are
variable names
It is a syntax error to pass constant values or
expressions to the (const) reference parameters
70