foo not called in main Why it needs input ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

foo not called in main Why it needs input ?

#include <iostream> using namespace std; int foo(int bar){ cin>>bar; cout<<bar; } int main() { // foo(0); return 0; }

27th Jul 2016, 5:15 PM
Jetset Willy
Jetset Willy - avatar
3 Answers
+ 2
When we use "int foo(int bar){return 0;}" , it means whenever we have to call "foo()" it needs to be passed with a integer value in it , like "foo(54)". If you want to insert value of "bar" from user(at runtime" you can use this one. #include <iostream> using namespace std; int foo(){ int bar; cin>>bar; cout<<bar; return 0; } int main() { foo(); return 0; }
28th Jul 2016, 5:25 AM
Preetam Daila
Preetam Daila - avatar
+ 6
Just Curious to know.. what is foo?
15th Sep 2016, 11:02 AM
Mr.Robot
Mr.Robot - avatar
+ 1
it's weird that it's commented out... but the input would allow you to set a different default value before user input every time you call the function but it does seam useless here. I might be missing something.
28th Jul 2016, 12:15 AM
Alexander Drinkwater
Alexander Drinkwater - avatar