- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
IT, Programming, & Web Development › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 2: [Arrays] – Functions, Variable and Scope, Debugging, Arrays, and Command Line Arguments › Void function and returning values
Reproducing part of Lecture 1 below:
“We can even change our meow
function to take in some input, n
, and meow n
times:
[dm_code_snippet background=”yes” background-mobile=”no” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
#include <stdio.h> void meow(int n); int main(void) { meow(3); } void meow(int n) { for (int i = 0; i < n; i++) { printf("meow\n"); } }
[/dm_code_snippet]
The void
before the meow
function means that it doesn’t return a value, and likewise in main
we can’t do anything with the result of meow
, so we just call it.”
To me, it returns a value, which is “meow\n”. Once meow function called, it is generating an output, which to me returning a value. I know I am perhaps unable to differentiate between calling without value and calling with value. Help appreciated.
Reply
https://edstem.org/us/courses/176/discussion/900183?comment=2052583[learn_press_profile]