Functions in C++ - Reading Assignment

  1. a function is a collection of instructions to perform a particular task that we need done.
  2. main()
  3. a return value is anything that a function is intructed to output back into the global execution context, so that another function that called upon it has some value to work with.
  4. nested functions are not allowed.
1 Like

What is a function? A string of executable code with a purpose.

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

What are return values? A return value from a function, in C++ it can be 0 for true and 1 for false.

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

1 Like

A return value can be any type defined for the function. :slight_smile:

  1. What is a function? 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? Returned values after calling a function
  4. Are nested functions allowed in C++? No, it’s not like JS, functions should be definied outside other functions
2 Likes

1.What is a function?
A-Data sequence that will execute a task, it’s bundled together enabling reusability.

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

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

  3. Are nested functions allowed in C++?
    A-NO, just NOOO…

2 Likes
  1. A function is a reusable block of code which you can use in your program.

  2. Main is the function that runs first and that holds all the functions.

3.Return value is the speciffic value which a function will return to the user. This is indicated by the type of value written on the left of the function name.

  1. No, you can’t nest functions in C++ so you have to write them separately.
1 Like

Ans 1:
A function in C++ is a statement that executes. Functions can consist of a collection of statements, thus enabling them to execute sequentially.

Ans 2:
The program that is run first in C++ is known as ‘main.’ Every program written in C++ must start with this function in order to be able to run.

Ans 3:
Return values are values that are returned as a result of using an keyword such as integer (‘int’) or a string (‘string’). Void keyword prefix (‘void’) does not return a value.

Ans 4:
Nested function declarations are not permitted in the convention of C++ coded language.

1 Like
  1. What is a function? A repeatable section of code that that can be called to perform a specific task.

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

  3. What are return values? These are the values returned by a called function to the caller.

  4. Are nested functions allowed in C++? Yes, but functions can not be defined within another function.

1 Like

That is the definition of a nested function and this is not supported in C++. :slight_smile: calling another functions from inside a function is ok

Ok, I was under the impression that the definition of nested function was a function CALL within another function, not a function being DEFINED within a function (which is not allowed).

On a side note, what is the exit code of main() being returned to?

You can pass a code to the calling program (like a shell) the status of the program at the end of the execution. Its mostly used to notify that the program executed with an error.
0 usually signals that the program executed correctly and any non zero value that the program encountered an error during execution. The code number is determined by the developer. :slight_smile:

  • 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
    int main()

  • What are return values?
    The values that are returned(to the caller) from functions

  • Are nested functions allowed in C+

1 Like

What happened to the final question? :slight_smile:

  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 specific value returned from a function.
  4. Are nested functions allowed in C++? No functions cannot be defined inside other functions.
1 Like
  1. A function is a portion of code that is reusable and is designated to do a specific job based off what you input into the function body.

  2. The function that is ran first in a C++ program is the main() function.

  3. Return values are the values that a function returns once it’s finished running.

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

1 Like

1.) A Function is a reusable sequence of statements to do a particular job.

2.) The 1st function run is the main () function.

3.) Return values are values that are sent to the caller from a function.

4.) Nested functions are not allowed in C++.

Quiz:

1a.) Will Print 16.
1b.) This will not work, C++ can’t do nested functions.
1c.) Will not produce an output.
1d.) Prints A & B on separate lines.
1e.) Produces an error, (will not compile.)
1f.) Prints the number 5 on separate lines.
1g.) This will not compile.
1h.) This will not compile without parentheses in the function call.

2.) DRY, “Don’t Repeat Yourself”. It is a practice in writing your code in such a way to minimize redundancy.

1 Like
  1. What is a function?
    A function is a block of organised, reusable code that is used to perform a single, related action.

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

  3. What are return values?
    It depends on the function that you created. In C++ Int function have to return ether 0 or 1

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

1 Like

A function that returns an int can return any integer value :slight_smile:

1 Like
  1. A function is a reusable sequence of statements designed to carry out a particular task or set of tasks.
  2. The main() function is called first
  3. The specific value returned from a function
  4. No, nested functions are not supported
1 Like