Hi! Every I need your help.
How can I terminate a function?
This is a discussion on function terminator within the C Programming forums, part of the General Programming Boards category; Hi! Every I need your help. How can I terminate a function?...
Hi! Every I need your help.
How can I terminate a function?
Use a return statement.
If you are having an infinite loop inside,it may also cause a never ending function. Use "break" in that case.
Return will work in the case of an infinite loop, if it is inside the body loop of course.
When the code of the body of the function reaches an the keyword, it will terminate, no matter what.
break keyword, will stop the loop and will transfer the flow of your code after the body of the loop.
Of course, you can use a "return", even if your function is of return value void.
Example.
Code:void foo(int a) { if(a < 5) return; ... }
Code - functions and small libraries I use
__________________________________________________ __________________________________________________ ______________
It’s 2013 and I still use printf() for debugging.
Thanks!)