Lecture 6 - Pointers and Functions Flashcards
data type that “points” to another value stored in memory
Pointers
marks the variable as a pointer
Asterisk
returns the variable’s address
Reference Pointer (&)
returns the value stored in a memory address
Dereference Pointer (*)
a set of statements that take inputs, does a specific task or computation to produce a certain output.
Functions
Built-in programs already available in C++, its functions are already available for use and will no longer require additional modification or programming.
Pre-Defined / Built-in
Created and modified by the user or programmer. Functions defined by programmers to suit the specifications set.
User-Defined
A built-in function in C++ by using header files or libraries where modification is not allowed
Pre-defined
A variable declared within a block and not accessible outside of that block.
Local Variable
How to declare functions?
dataType function_name (parameter list)
the variables or inputs of a function
parameter list
A variable declared outside of all the functions in a program and is accessible throughout the program.
Global Variable
it creates the function and is divided into two sections
Function Definition
defines the name of the function, the type of data to be returned, and the parameter list
Function Header
Parts of a Function Definition
Function Header & Function Body
defines the specific task to be carried out by the function. The whole function is enclosed using opening and closing
brackets
Function Body
also called a function prototype. It resembles that of a function header but with a semicolon and used to show how a function should be called and is useful in instructing the main function that this specific user defined function is existing in the C++ program
Function Declaration
is an expression which executes the function. If the function has
arguments, this needs input inside the parenthesis to do the particular task.
Function Call
Functions which return one value to the user once it is called in the program. The return type of this type of function is the one also used in the function definition.
Value Returning Function
The calling of a function requires data to be transferred forward and backwards, and if the parameter list in a function call is not empty, then data transfer will occur.
Exchange of Data
Created and used just like value-returning functions except they do not return a value after the function executes. It performs a task, and then control returns back to the caller but it does not return a value.
Void Function
passed to the function were copies of their values but never the variables themselves.
Pass by Value
not passing a copy of its value, but we are somehow passing the variable itself to the function.
Pass by Reference
A copy of value is passed to the
function
Call by Value
An address of value is passed to
the function
Call by Reference
specify more than one definition for a function name or an operator in the same scope
Function Overloading