- 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.
Software programming learning aide
CS50 threads to aide as a supplementary resource › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 2 › Understanding void and return 0/1 with an example
#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");
}
}
In Lecture 1, along with the above code, it is mentioned:
“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.”
I thought to make meow function return a value and so tried with this code:
#include <stdio.h>
int meow(int n);
int main(void)
{
meow(3);
}
int meow(int n)
{
for (int i = 0; i < n; i++)
{
printf("meow\n");
}
return 1;
}
This compiles successfully. I need to confirm if return 1 in the above code means that the program runs successfully. Or what is the utility of return 1? Can any function be made int type with bringing in return 0/return 1? Return 0 leads to non compiling in the above instance. My hunch (which actually perhaps not true) is suppose I make any error within the function meow and return 0 should lead to successful compilation as return 0 ensures that the program was unsuccessful in running.
Reply
https://edstem.org/us/courses/176/discussion/909123?answer=2070762[learn_press_profile]