Return Statement In A Void Function | C Programming Tutorial

  Рет қаралды 14,287

Portfolio Courses

Portfolio Courses

Жыл бұрын

How to use a return statement in a void function in C. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

Пікірлер: 28
@fifaham
@fifaham Жыл бұрын
Your videos are great review for guys who studied C few decades ago and want to refresh. Thank you Kevin.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I'm glad you think so Firas! :-)
@lenardskie
@lenardskie Жыл бұрын
I've never thought we could use return statement like that. Nice vid as always! I've been binge watching your tutorials to build a project for one of our subject XD
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you James for the positive feedback and for watching the tutorials, I hope your project goes well! :-)
@amineaitsaidi5919
@amineaitsaidi5919 2 ай бұрын
Void duncions can also return values, but hir their is no restrictions about it's type, you can return multiple type of values in the same function. Juste remember to make structure your program so that the void function don't return a value to a variable that is not compatible with it's type.
@Erlisch1337
@Erlisch1337 Жыл бұрын
Thought I knew all this already but I didnt know about returning another void function call ("return length_error();"). Neat.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Cool, I'm glad to hear that! 🙂
@alexandrstrekalovskiy4083
@alexandrstrekalovskiy4083 Жыл бұрын
Красавчик! Очень полезные видео! Давай ещё!)
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Благодарю! 🙂
@massimorusso3894
@massimorusso3894 Жыл бұрын
Grazie Professore sto imparando funzione del C che non sapevo 👍👍
@PortfolioCourses
@PortfolioCourses Жыл бұрын
È fantastico! :-)
@poisonmods
@poisonmods Жыл бұрын
So helpful 🙂
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I'm glad it was helpful! :-)
@germankoga8640
@germankoga8640 Жыл бұрын
Could you make a video covering the topic of Regex? (regular expressions I think).
@PortfolioCourses
@PortfolioCourses Жыл бұрын
That is definitely a topic on my list to cover. :-) That's a big topic though so it will take me awhile to get it (along with some other topics I'm dying to get to like makefiles...).
@Awwe12675
@Awwe12675 Жыл бұрын
Thank you
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome! :-)
@ramakrishna4092
@ramakrishna4092 Жыл бұрын
Hi sir I think instead of using return in c we can use EXIT_SUCCESS, EXIT_FAILURE instead of 0 or non zero value . I have seen many people or programmers don't explain about exit sucess and exit failure can you tell me the difference and why it's used ..
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Using EXIT_SUCCESS will exit the program with status 0/success, and EXIT_FAILURE will exit the program with status 1/failure.
@ramakrishna4092
@ramakrishna4092 Жыл бұрын
Hi sir useful information about Return keyword Thanks a lot . What happens when we do not use return statement in the calling function in C?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
By calling function do you mean the main function? We should use a return in main, but if we don't it will default to exiting with 0/success.
@Jorhie
@Jorhie Жыл бұрын
hey! which IDE are you using?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
In this video I am using XCode on a Mac. :-)
@alexk4894
@alexk4894 Жыл бұрын
./program && echo "executed successfully" || echo "Failed!" Your program returns 0 but actually fails with error. I think it would be better to use exit(1) instead. If I'm wrong please correct me. (exit code should be set depending on OS/environment)
@PortfolioCourses
@PortfolioCourses Жыл бұрын
The program does not fail with an error, the program exits with a status of 0, which means "success". The source code for the video is available here: github.com/portfoliocourses/c-example-code/blob/main/void_function_return.c. We can get the exit status of the last program run with the command echo $?, and it is 0 after running this program, which means it did not "fail with an error". A main function in standard C has to return a value (see: kzfaq.info/get/bejne/fthho92f0anIZGg.html). So we're going to need to use a return at some point in the main regardless, so we just return 0 (success), especially given this is just a simple 'demo program' for using return in a void function. We could use the exit() function too, yes, if we did that we would probably want to use EXIT_FAILURE an EXIT_SUCCESS as arguments, which are just preprocessor constants for 1 and 0. We would definitely want to use exit() if we want our program to stop execution in functions other than main, or if we have functions setup to run at exit using atexit(): kzfaq.info/get/bejne/f9Fjod2h05uwn3k.html.
@michaelfrankel8082
@michaelfrankel8082 6 ай бұрын
Just because you can do it doesn't meant you should do it.
@eyoelmekonnen3617
@eyoelmekonnen3617 Жыл бұрын
Hi...Can you please make a video on how the printf function is implemented in detail Thank you.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
This is on my list of video ideas Eyoel, I've had a number of people request a video on this topic. The only issue is that creating printf() is fairly involved, it's not a simple problem to solve so it's going to be awhile before I can do that video. Implementing the placeholders in printf() is not too bad, that's like this example here: www.equestionanswers.com/c/c-printf-scanf-working-principle.php. But once we get into implementing things like precision, fields, etc, it becomes a large and challenging problem. 🙂
Absolute Value Functions abs() And fabs() | C Programming Tutorial
3:40
Portfolio Courses
Рет қаралды 9 М.
How To Return An Array From A Function | C Programming Tutorial
13:01
Portfolio Courses
Рет қаралды 64 М.
Идеально повторил? Хотите вторую часть?
00:13
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 7 МЛН
ЧУТЬ НЕ УТОНУЛ #shorts
00:27
Паша Осадчий
Рет қаралды 10 МЛН
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 54 МЛН
why are switch statements so HECKIN fast?
11:03
Low Level Learning
Рет қаралды 394 М.
why do void* pointers even exist?
8:17
Low Level Learning
Рет қаралды 344 М.
Return Statement | C | Tutorial 17
8:04
Giraffe Academy
Рет қаралды 31 М.
are "smart pointers" actually smart?
9:44
Low Level Learning
Рет қаралды 72 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 756 М.
Function Pointers | C Programming Tutorial
18:31
Portfolio Courses
Рет қаралды 58 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2,1 МЛН
How To Return A String From A Function | C Programming Tutorial
13:51
Portfolio Courses
Рет қаралды 15 М.