What's wrong with this code?

why does it show error?

@priyamthakuria27 use void


dont forget to hit like and mark resolved if cleared :smiley:

there is a return 0; statement.
why is it not working?

i dont want to print anything. check this code.


once in for loop, it gets the return 0;, it should have returned. why error?

@priyamthakuria27 you are returning something so when calling the function store it in some var

i dont want to return anything.
that’s why return 0; is used.
we never store zero in some variable and return do you?

@priyamthakuria27 ok brackets were missing
#include
using namespace std;
int check() {
for(int i=1;i<=10;i++){}

return 0;

}
int main() {
check();
}

no.
i dont need those brackets.
#include
using namespace std;
int check() {
for(int i=1;i<=10;i++) {

return 0;

}

}
int main() {
check();
}

tell me, why this doesn’t work?

@priyamthakuria27
#include
using namespace std;
int check() {
for(int i=1;i<=10;i++)
{
return 0;
}
return 0;
}
int main() {
check();
}
return 0 missing outside
is it ok now?

no.
return statement when it gets, in the loop, tab hi pehli baar, kyu return nahi ho jata?

@priyamthakuria27 yes it will return first time only in the loop but still you have to write it in end otherwise error will come end of non void function as you can see. its syntax

arre, kyu?
syntax thori.

For functions where you have declared them with a return type other than void, you need to make sure that they contain a return statement; or in other words, ensure that the functions actually return something.

void main() {}

Now most programming languages use main() as the primary function. (that’s where the execution of a program begins) What does void mean here? Well, it means that the return type is void, ie. the function returns no value.

int main() {return 0;}

In C++ though, or at least in DEV C++, you need to initialize main with int as the return type; and hence the function returns a 0 at the end, indicating a successful execution of the programme.

int check() {
}
has a return type as well as a return statement inside the for loop which will be read.
i don’t understand, what you are saying.

@priyamthakuria27 bro its necessary you have to write return statement for the function too it will not work otherwise. i told you the reason above
just like you have to write int main function and declare header files and all you have to do this too
every programming language have its rules and regulations

For functions other than void you need to store the returned value in some variable. It is its syntax and without storing the value in the variable your code will not run.