Functions in C++ - Reading Assignment

Welcome to the discussion about the reading assignment about Functions in C++.

Leave your answers to the questions below in this thread. If you have any questions or you want to discuss something connected to the assignment feel free to do it in this thread as well, but please everything to the topic.

  1. What is a function?
  2. What function is run first of all in a C++ program?
  3. What are return values?
  4. Are nested functions allowed in C++?
18 Likes
  1. piece of code that can be called, interrupting and bookmarking the current location, it can have void return value or return and actual value to the calling function which will pick up at the bookmarked location
  2. int main()
  3. a value returned to the calling function that can be assigned or used in an expression
  4. no, a function can not be defined in another function
1 Like
  1. a reusable sequence of statements
  2. main()
  3. the values that are returned (to the caller) from functions
  4. no

1. What is a function?
A sequence of statements that can be reused.

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

3. What are return values?
When you call a function, she will return you values. When a function returns value, you have to specify the type of this value just before the name of the function when you declare her.
Ex: int myFunction() { return 0; } //return an Int

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

NOTE: Don’t forget to declare your function above the main() function. Otherwise, the main function would not find her.

2 Likes

What is a function?
reusable data sequence that will execute a task
What function is run first of all in a C++ program?
int main(){
return 0; (optional because the compiler will already assume)
}
What are return values?
Data that is sent to the caller from a given function
Are nested functions allowed in C++?
“NEEEEVVEEERRR!” Bellatrix voice

  1. A callable sequence of statements.
  2. main()
  3. value that outputted by a function
  4. Functions cannot be defined inside of other functions in C++
  1. A function is a sequence of code doing a specific task, bundled together enableing 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++
  1. What is a function?
    A sequence of predefined statements designed to execute a task based on the definition of those statements.

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

  3. What are return values?
    The TYPE of value that a function returns.

  4. Are nested functions allowed in C++?
    Yes, as soon as pigs fly so, NO WAY!

1- Function is a chunk of code used to specify the program executions to do when it is called
2- Entry point function in C++ is named main and must return an int
3- Return values are the data which is returned by a function when it ends operations
4- Nested functions are not allowed in C++

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?
The main() function.

3. What are return values?
Return values are what a function returns after it finishes executing.

4. Are nested functions allowed in C++?
No. Nested functions are not allowed in C++.

1. Reusable sequence of statements designed to do a particular job.

2. main()

3. The actual values returned from a function indicated by a return statement.

4. No.

What is a function?
- A function is a reusable set of code to perform a particular task.

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

What are return values?
- The values which are returned at the end of a function to the caller function.

Are nested functions allowed in C++?
- No. They should be called within one function and then executed in another.

What is a function? sequence of statements designed to do what the program have to do
What function is run first of all in a C++ program? main()
What are return values? The actual value returned from a function
Are nested functions allowed in C++? NO

  1. What is a function?
  2. Like JavaScript, in C++, a function is a reusable statement of particular series of operations to complete a process.

  3. What function is run first of all in a C++ program?
  4. The first function ran in all C++ projects is main().

  5. What are return values?
  6. Unlike in JavaScript with call backs, in C++ functions return a value of 0 for true or 1 for false. They can also return other values like in JavaScript call backs as manipulations of the input type. They can return strings, integers and also void indicating no return value to the caller.

  7. Are nested functions allowed in C++?
  8. In C++ nested functions (functions inside of functions) are not allowed. The proper way is to define the function beforehand and then call the function while inside another function.

Quiz Results

  1. The first answer will print out 16 and then return the value 0.
  2. This returns an error due to declaring a nested function.
  3. This will return 0 because no cout has been accessed.
  4. This will print out A the B in the next line. Finally it will return with the value 0.
  5. This will not compile due to invoking std:cout to a function that is already doing this.
  6. When a function returns a value the statement is executed. So five is printed twice.
  7. The function return 5() is not a valid function name andtherefore will not compile.
  8. In the main function the function return5() is missing the parenthesis.
  1. A function is a reusable sequence of statements designed to do a particular job.
  2. int main()
    3.The actual value returned from a function is called the return value.
    4.no

1- A function is a reusable sequence of statements designed to do a particular job.
2- every program must have a function named main() (which is where the program starts execution)
3- 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- Functions can not be defined inside other functions (called nesting) in C++.

Quiz :
1a) Prints 16.
1b) Not working (function can not be inside other function(Nested).
1c) Not producing any output.
1d) Prints A and then prints B on the next line.
1e) No returning value from the function and therefore it will not compile.
1f) Prints two number 5 on separate lines.
1g) The function has an invalid name so it won’t compile.
1h) The function is called without parentheses so the output is unknown.

What is a function?
A function is a piece of easily repeatable, callable code

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

What are return values?
return values are the offspring of a function after it has passed away… These values can be used in an expression or assigned to a variable.

Are nested functions allowed in C++?
Absolutely not.

  1. a function enables us to reuse code which does a specific task, for example a function which returns the largest value of a given array.
  2. the main function runs first
  3. the value which is returned from the function.
  4. nested functions are NOT allowed in C++
  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++.

What is a function?

A function is a set of instructions that is predefined and can be called at any time, interrupting the current flow of the program. Some functions take parameters and some functions don’t. Some functions return a value and some functions don’t.

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

The main function!

What are return values?

Return values are output by the function after the function is finished its purpose. The type of return value is determined when defining the function (void, int, string, double, etc.).

Are nested functions allowed in C++?

No.