Functions in C++ - Reading Assignment

Answers

  1. A function is a reusable sequence of statements designed to run a particular task.

  2. The function that is ran first of all C++ programs is the main().

  3. Return values are the actual values returned from a function indicated by a return statement.

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

1 Like

1.reusable sequence of statements designed to do a particular job.
2.main()
3.Data that is sent to the caller from given functio.
4. no

1 Like

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?

a function named main

What are return values?

The specific value returned from a function is called the return value.

Are nested functions allowed in C++?

Nested functions are not supported

Unlike some other programming languages, in C++, functions cannot be defined inside other functions.

1 Like
  1. What is a function?

A reusable sequence of statements designed to do a particular job

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

The main function

  1. What are return values?

the value given to the caller after completion of a function

  1. Are nested functions allowed in C++?

No

1 Like

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?
Returned values are specific values returned from a function

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

1 Like
  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?
    It is a specific value returned from a function that you wrote.

  4. Are nested functions allowed in C++?
    Function’s can not be nested

1 Like
  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 to the caller is called the return value.

  4. No, nested functions are not allowed in C++

1 Like
  1. A function is a reusable sequence statements that get executed to achieve a computation
  2. Main function
  3. The specific value returned by a function.
  4. No
1 Like

1.A function is a reusable sequence of statements designed to do a particular job.
2. main().
3. A function can optionally return a value as output. Functions are useful for encapsulating common operations in a single reusable block, ideally with a name that clearly describes what the function does.
4.No, you can execute another function inside the main function but you have to call it , not declare it. The declaration of the called function must be outside the main function.

1 Like
  1. What is a function? A piece of code that could be separate from the principal part of the program to do a particular processing one or more times.
  2. What function is run first of all in a C++ program? main()
  3. What are return values? The values that a function output.
  4. Are nested functions allowed in C++? No.
1 Like
  1. What is a function?
  • A function is a block of code that performs a specific task and can be reused.
  1. What function is run first of all in a C++ program?
  • The function called “main()”.
  1. What are return values?
  • Return values are the values that are returned by a function to the calling function. If the function is declared of the “void” type, there is no value returned.
  1. Are nested functions allowed in C++?
  • Nested functions (defining another function within a function) is not allowed. However, a function can be called by a function which can itself call a function, etc.
1 Like

Hi everybody,
Can someone please explain to me this:
How to write this code without using “using namespace”:
#include
#include

using namespace;
string FunctionName (string text){
return “Hi” + text;
}

int main () {
cout << FuntionName (Sport);
return 0;

Also should I use using namespace or not. I found somewhere that c++ community recommended to not use it,
Thank you

  1. What is a function?

A function is a set of instructions that can be used repeatedly by the main program.

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

int main()

  1. What are return values?

Return values are final output values of functions.

  1. Are nested functions allowed in C++?

No

1 Like
  1. A reusable sequence of statements.
    2.main()
    3.values that are returned to the caller through a function.
    4.No. you can not nest functions in C++
1 Like

Namespaces are a way of separating different parts of code, but are not necessary, at least not for small applications. For the most part you don’t need them.

As for your code example, I’m not entirely sure what you intend to do? include don’t include anything and namespace is not named, it should be using namespace NamespaceName.

Have you tried removing the namespace line and see if your solution still works?

Sorry- should be namespace std;

Ahh, yes using functions in the std namespace requires either using namespace std or explicitly calling the function with a prefix std::functionName.

So if you want to call cout without the std namespace, you will have to call the function using std::cout.

1 Like

Thank you,
This works:
#include

using namespace std;

string Greetings(string name){

return name;

}
int main()
{
string name = “”;
cin >> name;
cout <<name << " is my name, sir";

return 0;

}
But how to do it without “using spacename std:”?

Replace cin and cout with std::cin and std::cout.

1 Like
  1. Reusable code that executes particular commands in particular order considering particular conditions. Functions may or may NOT take input or generate output (but usually they do).
  2. The main() function.
  3. This is the output of a function which can be used or stored in variable after the function is processed.
  4. No.
1 Like