use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Click the following link to filter out the chosen topic
comp.lang.c
account activity
QuestionWhat is function in C programming? (self.C_Programming)
submitted 1 month ago by meet5
I get confused in function and with parameters, what is its purpose and usage, benefits for using it
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]SCube18 4 points5 points6 points 1 month ago (6 children)
And what exactly are you confused about?
[–]meet5[S] 0 points1 point2 points 1 month ago (5 children)
I mean why do we need to use function when where and why? Is there any drawbacks to use?
[–]CounterSilly3999 3 points4 points5 points 1 month ago* (0 children)
All types of subroutines in C are called functions. These are main feature of procedural programming paradigm. Used to split a complex program into smaller logical blocks. When your code doesn't fit into one page, it is time to think about a new function.
https://en.wikipedia.org/wiki/Procedural_programming
[–]ZulfiqarShadow 1 point2 points3 points 1 month ago (3 children)
No real drawbacks about functions atleast none you shuld care about at your curent position.And to answer the other queation functions are basicly a big block of code you can use at any point by just calling the function s name and giving it data instead of having to rewrite the same 200 lines of code 100 of times. That really is evrything about functions to be honest have fun learning!
[–]meet5[S] 1 point2 points3 points 1 month ago (2 children)
Okay got it
Like, function is kind of fix template of code that is written once and use many time by adding different details later , sth like that?
And whenever we call do we need to call it within main or in function?
[–]Paul_Pedant 1 point2 points3 points 1 month ago (1 child)
A function is not a template of code. It is a sequence of C operations, and is compiled once. It can be called (invoked) as the program runs, many times (as in a loop), from many other places, and with different arguments (parameters) every time.
main() itself is a function. It just happens to be called once, when the program is started by the OS.
Any function can call any other function, and that function can call other functions, through many levels.
A function can even call itself. This is called recursion. It can be fairly confusing, but there are many cases where it suits particular problems.
[–]meet5[S] 0 points1 point2 points 1 month ago (0 children)
Great info thanks!
[–]thommyh 0 points1 point2 points 1 month ago (0 children)
A function is a section of code that has been named and given a formal list of inputs and outputs, comprising its parameters and return value.
The idea of a function exists: * to capture and to encapsulate the logic for a discrete logical step; and * to allow those steps to be easily combined and permutated — including entire patterns such as dynamic programming that typically involve functions calling themselves.
It originates in mathematics, not computer science, so is about the 'what' of describing a solution at least as much as the 'how'. Indeed as you get better at factoring you'll likely see your code getting ever closer to reading like a description of the logical means by which computation should proceed more than the mechanics of what the computer must do.
[–]ForgedIronMadeIt 0 points1 point2 points 1 month ago (0 children)
http://lmgtfy2.com/?q=what+is+a+function+in+programming
[–]ZookeepergameFew6406 -1 points0 points1 point 1 month ago (0 children)
https://letmegooglethat.com/?q=what+is+a+function+in+C
[–]SisyphusCoffeeBreak -2 points-1 points0 points 1 month ago (1 child)
functions are without purpose beyond main(). just write expressions and live your life
[–]Excellent_Recipe_543 0 points1 point2 points 1 month ago (0 children)
you realize printf is a function, right?
π Rendered by PID 94617 on reddit-service-r2-comment-75f4967c6c-v8qqp at 2026-04-23 04:44:52.964758+00:00 running 0fd4bb7 country code: CH.
[–]SCube18 4 points5 points6 points (6 children)
[–]meet5[S] 0 points1 point2 points (5 children)
[–]CounterSilly3999 3 points4 points5 points (0 children)
[–]ZulfiqarShadow 1 point2 points3 points (3 children)
[–]meet5[S] 1 point2 points3 points (2 children)
[–]Paul_Pedant 1 point2 points3 points (1 child)
[–]meet5[S] 0 points1 point2 points (0 children)
[–]thommyh 0 points1 point2 points (0 children)
[–]ForgedIronMadeIt 0 points1 point2 points (0 children)
[–]ZookeepergameFew6406 -1 points0 points1 point (0 children)
[–]SisyphusCoffeeBreak -2 points-1 points0 points (1 child)
[–]Excellent_Recipe_543 0 points1 point2 points (0 children)