FAQ: Functions - Void — The Point of No Return

This community-built FAQ covers the “Void — The Point of No Return” exercise from the lesson “Functions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C++

FAQs on the exercise Void — The Point of No Return

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Would have been helpful if you stated explicitly that you did not want us to print the quotation marks around the oscar wilde quote. I just spent ten minutes looking for a bug in my code that wasn’t there.

3 Likes

Try again using:
void oscar_wilde_quote(){
std::cout << “The highest, as the lowest, form of criticism is a mode of autobiography.\n”;
}

1 Like

i wrote the quote wrong :joy:

1 Like

Inside of main() , call `oscar_wilde_quote() I dont know wat to do can someone help me

You need to std::cout a string in the function oscar_wilde() and then call that function inside the int main().

1 Like

It would be nice to know that you don’t need to enter return before function because all previous examples had return marked as a blue operator before declared function. This was very off-putting!

I can’t understand this: Inside of main() , call oscar_wilde_quote(). Can anybody help me? :confused:

int main() {
// Call your function here:

oscar_wilde_quote() ;

}

1 Like

Cannot understand this topic.What happens after calling that function again?

When you define a function, nothing happens. So, when you define the oscar_wilde_quote() function and then run the program, you will see nothing being printed to the console.

It is when you actually call the function that the instructions within the function are executed. When (in your main function) you call the oscar function, that is when the std::cout statement within that oscar function is actually executed and you will see the quote being printed to the console.

Think of it like cooking. When you define a function, you are writing a recipe in your notebook but aren’t doing any cooking. When you call that function, then you are actually cooking by enacting the steps outlined in the recipe.

2 Likes

I don’t know what I’m doing wrong
I’ve been trying this lesson for half an hour, and nothing works. This is what I have so far

#include

// Define oscar_wilde_quote() below:
void oscar_wilde_quote(){
std::cout << “The highest, as the lowest, form of criticism is a mode of autobiography.\n”;
}

int main() {

// Call your function here:

}

If someone could tell me what I’m doing wrong and give the correct thing, I would appreciate it.

You have completed Step 1 of the exercise i.e. defining the function.
Step 2 asks you to call this function from main(). Note the comment // Call you function here: which points out where in main you are supposed to call the function you have defined. To call a function with no parameters, you just do function_name() where function_name should be replaced by the name of the function you are calling.

2 Likes

When I hit the “Show answer” button, all it added was white space in between all my lines.

okkayyy I see why everyone is getting stuck… my problem should be similar to others, instead of writing block of code

-void oscar_wilde_quote() {
std::cout << “The highest, as the lowest, form of criticism is a mode of autobiography.\n”;
}

-int main(){

make sure you read the instructions and place that block of code above int main(){

and don’t forget to call your function under int main(){
//write here
}

I don’t know why I am getting stuck help me !!
void oscar_wilde_quote() {

std::cout << “The highest, as the lowest, form of criticism is a mode of autobiography.\n”;

}

int main() {

ocsar_wilde_quote();

}
ANd keeps saying "make sure oscar_wilde_quote() is define above int main() and called inside main()."

In main, you have misspelled oscar as ocsar.
Also, the instructions don’t specify that you should include the newline character \n in the output.

1 Like

Is there any difference between this:

#include <iostream>

// Define oscar_wilde_quote() below:
std::string oscar_wilde_quote() {
  std::string quote = "The highest, as the lowest, form of criticism is a mode of autobiography.\n";
  return quote;
}

int main() {
  
  // Call your function here:
  std::cout << oscar_wilde_quote();
  
}

And this:

#include <iostream>

// Define oscar_wilde_quote() below:
void oscar_wilde_quote() {
  std::cout << "The highest, as the lowest, form of criticism is a mode of autobiography.\n";
}

int main() {
  
  // Call your function here:
  oscar_wilde_quote();
  
}

?

I mean any difference with the performance or any other aspect, the result is the same.

1 Like

If printing the quote to the terminal is the only objective, then both approaches will work. Indeed, the void function will make for more concise code. But, if we intend to do something with the quote like editing the quote or something else, then the function with return is more appropriate.
Also, suppose we wanted to print the quote 100 times. Then, the function with return would offer us better performance. From main(), we could make a single call to our function and save the result to a variable in main. Then, we could print the variable 100 times with a loop. With the void function, we would have to write a loop in main which would make 100 function calls. That would affect performance.

int main()  {
  // Calling the version of function which has return
  std::string result = oscar_wilde_quote(); // Single call to function
  for (int i = 0; i < 100; i++) {
    std::cout << result; 
  } 
}

as opposed to:

int main()  {
  // Calling the void version of function
  for (int i = 0; i < 100; i++) {
    oscar_wilde_quote(); // 100 calls to function 
  } 
}
1 Like

Thank you so much for the reply! :grinning: