Functions in C++ - Reading Assignment


#81

What is a function?
A function is a reusable sequence of statements designed to do a particular job.

What function is run first of all in a C++ program?
function named main()

What are return values?
The actual values returned from a function

Are nested functions allowed in C++?
No


#82
  1. A reusable sequence of statements designed to do a particular job.

  2. Main()

  3. The value returned from a function

  4. No


#83

1 A function is a reusable sequence of statements designed to do a particular job.

2 The main() function

int main() //as usually written

3 The value returned from a function.

4 Defining functions inside other functions.

int main(){
void foo()
{…}
} // wecan’t do that.


#84
  1. it’s a predefined algorithm that can be called in the middle of a programme, to hence be executed before the previously running programme can resume.

int main ()
{

}

  1. these help return the value of a predefined variable.
    for example.
    return a;
    such that a represents the value contained within itself.

  2. nested functions aren’t allowed in C++ .
    There’s simply no room for having functions within functions like a universe within a universe that’s within another universe.


#85
  • A function is a piece of code that does an action.
  • The First function executed by C++ is the “main” function.
  • The return value is a value stored resulting of a function and is stored in memory.
  • Nested functions are NOT allowed in C++.

#86

1. What is a function?

A function is a reusable sequence of statements designed to do a particular job.

2. What function is run first of all in a C++ program?

main() (which is where the program starts execution).

3. What are return values?

When the main() function finishes executing, it returns an integer value (typically 0) back to the operating system (the caller) by using a return statement.

When you write your own functions, you get to decide whether a given function will return a value to the caller or not. This is done by setting the return type of the function in the function’s definition. The return type is the type declared before the function name. Note that the return type does not indicate what specific value will be returned. It only indicates what type of value will be returned.

Then, inside the called function, we use a return statement to indicate the specific value being returned to the caller. The actual value returned from a function is called the return value .

4. Are nested functions allowed in C++?

In C++, functions cannot be defined inside other functions (called nesting ).

Source Example: http://www.learncpp.com/cpp-tutorial/14-a-first-look-at-functions/


#87

What is a function?

A function is a reusable sequence of statements designed to do a particular job.

What function is run first of all in a C++ program?

Main()

What are return values?

Return values are inside the called function that is a return statement to indicate the specific value being returned to the caller. This is the actual value returned from function.

Are nested functions allowed in C++?

Nested functions are not supported in C++, because there cannot be a function within a function without declaring a function an extension of the GNU compiler.

QUIZ

1a. Output is “6”

1b. This code will not compile since it’s a nested function

1c. This compiled but the returned values are not used by main and discarded.

1d. A and B on different lines

1e. This did not compile because Function printA() returns void, which main tries to send to std::cout. This will produce a compile error.

1f. Returned “5” on two separate lines, ignored “7”

1g. This has an invalid name so it will not compile

1h. Compiled “1” but could be anything depending on the compiler because the function is missing parenthesis.


#88
  1. What is a function?
    a function is a reusable sequence of statements designed to do a particular job
  2. What function is run first of all in a C++ program?
    main()
  3. What are return values?
    the actual value returned from a function is called the return value
  4. Are nested functions allowed in C++?
    no

#89

What is a function?

A reusable sequence of statements designed to do a particular job

What function is run first of all in a C++ program?

Function main().

What are return values?

A return value is an integer value returned back to the caller of a function when the function finishes executing. In the case of the function main() the return value is sent back to the operating system.

Are nested functions allowed in C++?

Nested functions are functions that are defined inside of other functions. Nested functions are not legal in C++.

1a. 16

1b. function return 9 is nested in return 7 so we will get a compile error

1c. No output. We have returned 7 and 9 but have not done anything with them

1d. A

B

1e. There will be no output. printA() does not have a return value. So we get a compile error

1f. 5

5

1g. Compile error due to empty space between return and 5()

1h. Parentheses missing in function call so program may not compile, or if it does compile, the function will not be called as expected


#90
  1. What is a function?
    A bunch of reusable code that can be called inside other functions, to avoid retyping of code and to facilitate code management.

  2. What function is run first of all in a C++ program?
    The main function => int main() {}

  3. What are return values?
    Values generated and outputs by functions and that end it’s execution when reached. Their type is defined along with the function name, at the top of the block. If the function doesn’t return any value, the type is “void”.

  4. Are nested functions allowed in C++?
    No. A function can’t be defined inside another, though it can be called.


#91
  1. A function is a reusable sequence of statements designed to do a particular job.

  2. int main() is the first of all run function in a C++ program.

  3. The value that gets returned from the function is the return value. Once it is returned the program stops.

  4. Nested functions are NOT allowed in C++.


#92

1. What is a function?

A function is a section of code that can be called from the main programme 1 or multiple times. The function can return a value or not. Functions are useful to avoid code repetition and to help keep code modular.

2. What function is run first of all in a C++ program?

The main section of the program is in itself a function, this is the "int main()" function and it is run first.

3. What are return values?

Return values are data that is passed back to where the function was called from. In c++ the function must be defined by the type of return it will produce, i.e integer, string, Boolean, etc. If no return is required then void is used.

4. Are nested functions allowed in C++?

Nested functions are allowed in c++ however all function definitions must be at the top level of the programme.

#93

1- A function is a portion of reusable code.
2- The function main() is the first that runs on C++
3- Return values are the value that is returned to the caller of the function
4- Nested functions are not allowed in C++


#94

1function is a reusable sequence of statements designed to do a particular job
2.Main(){}
3. Program that interested the ongoing function for another function
4.No


#95
  1. What is a function?
    A function is a reusable sequence of statements designed to do a particular job. You already know that every program must have a function named main() (which is where the program starts execution).

  2. What function is run first of all in a C++ program?
    int main()

  3. What are return values?
    The actual value returned from a function is called the return value

  4. Are nested functions allowed in C++?
    NO


#96
  1. What is a function?

    • It is a reusable sequence of statements designed to do a particular thing.
  2. What function is run first of all in a C++ program?

    • The main() function is the first one ran which is where the program starts execution.
  3. What are return values?

    • You decided whether a given function will return a value to the caller or not. We use a return statement to indicate the specific value being returned to the caller. The actual value returned from a function is called the return value.
  4. Are nested functions allowed in C++?

    • No you cannot have nested functions, they must be written separately.

#97
  1. A function is a reusable sequence of statements designed to do a particular job.
  2. main()
  3. The actual value returned from a function is called the return value .
  4. Functions can not be defined inside other functions (called nesting) in C++

#98
  1. A function is a of reusable sequence of statements designed to do a particular job.
  2. int main()
  3. Inside the called function we use a return statement to indicate the specific value returned to the caller. The actual value returned by the function is called the return value.
    4.nesting in c++ is not legal.

#99
  1. A function is a sequence of code doing a specific task, bundled together enabling reusability.
  2. The main() function
  3. When a function finishes it’s execution it has the option to return a value, as the result of it’s execution. This value is called a return value
  4. Nested functions are not allowed in C++

#100

What is a function?

  • A function is a reusable sequence of statements designed to do a particular job.

What function is run first of all in a C++ program?

  • The function named main() is where the program starts execution.

What are return values?

  • The actual value returned from a function is called the return value.

Are nested functions allowed in C++?

  • No. Functions cannot be defined inside other functions in C++