{"id":3180,"date":"2021-06-08T20:25:00","date_gmt":"2021-06-08T14:55:00","guid":{"rendered":"https:\/\/manorinfinity.com\/blog\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/"},"modified":"2021-06-08T20:25:00","modified_gmt":"2021-06-08T14:55:00","slug":"how-recursion-works-recursion-example-in-c-language-bitsofcs","status":"publish","type":"post","link":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/","title":{"rendered":"How Recursion Works | Recursion Example in C Language | BitsOfCS"},"content":{"rendered":"<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 12pt; margin-top: 12pt; text-align: center;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">&nbsp;<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-left: 11pt; margin-right: 11pt; margin-top: 0pt; margin: 0pt 11pt; text-align: center;\"><span style=\"font-size: large;\"><br \/><\/span><\/p>\n<h2 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 18pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">1. What is recursion?&nbsp;<\/span><\/span><\/h2>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">Any function(in your program) which calls itself is called a &#8216;<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">recursive function&#8217;<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> and this process is known as &#8216;<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; text-decoration-skip-ink: none; vertical-align: baseline; white-space: pre-wrap;\"><a href=\"https:\/\/en.wikipedia.org\/wiki\/Recursion_(computer_science)\" target=\"_blank\" rel=\"noopener noreferrer\">recursion<\/a><\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">&#8216;. A recursive function solves a problem by calling a copy of itself, by working on a smaller distinct of the actual problem. The recursion step must be terminated at some point.<\/span><\/span><\/p>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Example-&nbsp;<\/span><\/span><\/p>\n<p><span style=\"font-family: courier; font-size: large;\"><\/span><\/p>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">We have two ways to track recursion-<\/span><\/span><\/p>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<h2 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 18pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">1. Tracing the recursion using stack:<\/span><\/span><\/h2>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">In order to trace the recursion &#8216;<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; text-decoration-skip-ink: none; vertical-align: baseline; white-space: pre-wrap;\">stack<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> data structure&#8217; is used.<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Program Counter:<\/span><\/span><\/h3>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">A <a href=\"https:\/\/en.wikipedia.org\/wiki\/Program_counter\" target=\"_blank\" rel=\"noopener noreferrer\">program counter<\/a> is a register in the processor that has the address of the instructions that are being executed currently. When any instruction completes its execution, the program counter increases its stored value (address or ID) by 1. This program counter helps to keep track of the address or ID of those instructions in the program, which were not executed due to the function calling.&nbsp;<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">&nbsp;<\/span><\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Let&#8217;s understand every step one by one.<\/span><\/span><\/p>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">Step-1: <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">In our example we have the main()<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\"> <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">function, hence the first record of the stack, records the main() function. Inside the main() function we call the user defined function fun()<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\"> <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">and value <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">3<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> passed to the variable <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">n <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">in the actual fun() function.<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\"> <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">&nbsp;<\/span><\/span><\/h3>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Now due to the function calling, the program counter goes to the fun() function and remaining statements of the main() function will be executed after completion of the fun() function.<\/span><\/span><\/h3>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">In the main() function, fun(3) appears at the line number 5, so that, the program counter of the first record of stack has ID as 6, that tells whenever we will complete the execution of fun() then we have to come back at line number 6 for remaining execution of the program.<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-left: 18pt; margin-right: 18pt; margin-top: 14pt; margin: 14pt 18pt 4pt; text-align: center;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"border: none; display: inline-block; height: 245px; overflow: hidden; width: 602px;\"><span style=\"font-family: courier; font-size: large;\"><img loading=\"lazy\" decoding=\"async\" height=\"245\" src=\"https:\/\/lh3.googleusercontent.com\/LsTMc2UpeaCdYSlZr0F842lMcyJjI-9uQ7sBj2SAJezeBQMopfIUwS5nrLR5dMZ9_h5SD2Nn1ocHKy0sgoayHJ1yy0fM9Dx6P7EqUROgGi_KBuaSZ8RVpgZAPOZf8i17gqxvH1IC\" style=\"margin-left: 0px; margin-top: 0px;\" width=\"602\" \/><\/span><\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">Step-2: <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">&nbsp;Now fun() is a recursive function, because fun()<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\"> <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">calls itself. In fun(), <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">n=3<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> and n&gt;1 is true then it produces the output as <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">2<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> and again calls the fun() function with parameter n-1 i.e. <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">2<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">. Here, the second record of the stack has program counter ID as <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">13<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">.<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-left: 18pt; margin-right: 18pt; margin-top: 14pt; margin: 14pt 18pt 4pt; text-align: center;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"border: none; display: inline-block; height: 245px; overflow: hidden; width: 602px;\"><span style=\"font-family: courier; font-size: large;\"><img loading=\"lazy\" decoding=\"async\" height=\"245\" src=\"https:\/\/lh5.googleusercontent.com\/u1EuO2xvL-CIUNLmMSKs5CI4sPXLao710rth_F0bI1fDLQjeovf2RJ_tMOstszvy_FThij6HJZuZjsJ_a85eIZ-ZnxkE_L88gDkMpGJBdksPFVmTZa-uHQhtiODMs0QhAZmUsSbV\" style=\"margin-left: 0px; margin-top: 0px;\" width=\"602\" \/><\/span><\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">Step-3: <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">In the third record, <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">n=2<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> and n&gt;1 is true then it produces the output as <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">1<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> and again calls the fun() function with parameter n-1 i.e. <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">1<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">. Here, the third record of the stack has program counter ID as <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">13<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">.<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-left: 18pt; margin-right: 18pt; margin-top: 14pt; margin: 14pt 18pt 4pt; text-align: center;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"border: none; display: inline-block; height: 248px; overflow: hidden; width: 602px;\"><span style=\"font-family: courier; font-size: large;\"><img loading=\"lazy\" decoding=\"async\" height=\"248\" src=\"https:\/\/lh3.googleusercontent.com\/2-mg3iBaQDW3hTZeSg0kqAQt-U6kVwV2kVaFkNbLjLZXMcCZ04FhjaVr_NbYa4zGM6YJPYhFONLHy0_5dYlDUtRrlARs_UfQg6nyOUgLaM6OYdg4jzxwL2yGHvxfGRGqtu4eSJRF\" style=\"margin-left: 0px; margin-top: 0px;\" width=\"602\" \/><\/span><\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">Step-4: <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">In the fourth record, <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">n=1<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> and n&gt;1 is false. Hence, if the condition is false. This is the base condition of the recursion.<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-left: 13pt; margin-right: 13pt; margin-top: 14pt; margin: 14pt 13pt 4pt; text-align: center;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"border: none; display: inline-block; height: 248px; overflow: hidden; width: 602px;\"><span style=\"font-family: courier; font-size: large;\"><img loading=\"lazy\" decoding=\"async\" height=\"248\" src=\"https:\/\/lh5.googleusercontent.com\/ZaQEBPxwn8BXUhPOp9GxLJ2WbQA6zG6F4nPPSMH5ODL3eU52mWeht62dH2g2X-WNXsBDcEjcGyGqNVsmlNgU67FZiXQ5n4tc2t3kn9YLuDEgnd6SmPHSKrZRcwcGBI8epWfNKsve\" style=\"margin-left: 0px; margin-top: 0px;\" width=\"602\" \/><\/span><\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">Step-5:<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> Now, the fourth stack record completed its execution and popped out from the stack. Then, in the third record of stack, the program counter went to the line number <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">13<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> and completed the execution of the remaining statements and popped out from the stack. Same for the second record. Then, in the first record of the stack, the program counter go to the line number <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">6<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> and complete the execution of the remaining statement in the main() function and popped out.<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-left: 18pt; margin-right: 18pt; margin-top: 14pt; margin: 14pt 18pt 4pt; text-align: center;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"border: none; display: inline-block; height: 248px; overflow: hidden; width: 602px;\"><span style=\"font-family: courier; font-size: large;\"><img loading=\"lazy\" decoding=\"async\" height=\"248\" src=\"https:\/\/lh5.googleusercontent.com\/MzNmelQWJnNhcQcG9-3E7jzVPS6M6Y_FUwLlr_dRDY4R3sUHaVIlu_DoXSjgKIJw64qd2OEnFVil_duwjR4ZogHRN-3DiSeavIRNs6Cb-hy9OZnjDOu9sEv-RzfaLzb86UGdvYD2\" style=\"margin-left: 0px; margin-top: 0px;\" width=\"602\" \/><\/span><\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">This is how recursion works using stack data structure.<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<h2 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 18pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">2. Tracing the recursion using tree:<\/span><\/span><\/h2>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">This is a theoretical method to trace the recursion.<\/span><\/span><\/h3>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">Step-1: <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">In the main() function, we have to call the fun() function and the fun(3) function contains two functions.&nbsp;<\/span><\/span><\/h3>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">1. printf(&#8220;%d&#8221;, n-1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2. fun(n-1)<\/span><\/span><\/h3>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Here n=3 and n&gt;1 hence condition true<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-left: 18pt; margin-right: 18pt; margin-top: 14pt; margin: 14pt 18pt 4pt; text-align: center;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"border: none; display: inline-block; height: 262px; overflow: hidden; width: 332px;\"><span style=\"font-family: courier; font-size: large;\"><img loading=\"lazy\" decoding=\"async\" height=\"262\" src=\"https:\/\/lh3.googleusercontent.com\/XlmDJrQBh6f3L_68hdbjU4nUg7slRWWjHNpxaLtVtP1w6Nwkpry_MpPtF3UyZ3klK71K2OVTCUN9qioxII0qtFCZQ-JUWbr-NB0ELmRXleZQCupsXX03OWOTqSr3Eq9nzhhsWp7F\" style=\"margin-left: 0px; margin-top: 0px;\" width=\"332\" \/><\/span><\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">Step-2:<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"> Now, again fun(2) function contains two functions.&nbsp;<\/span><\/span><\/h3>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">1. printf(&#8220;%d&#8221;, n-1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2. fun(n-1)<\/span><\/span><\/h3>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">Here n=2 and n&gt;1 hence condition true<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-left: 18pt; margin-right: 18pt; margin-top: 14pt; margin: 14pt 18pt 4pt; text-align: center;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"border: none; display: inline-block; height: 292px; overflow: hidden; width: 402px;\"><span style=\"font-family: courier; font-size: large;\"><img loading=\"lazy\" decoding=\"async\" height=\"292\" src=\"https:\/\/lh4.googleusercontent.com\/2NXxmSLX1C9fr2eynxHAnzr4dKvEC4wHxE7lbJD7Yygz3J66XJPO-bG18R46KXME8xvCCx5Q8hjXx3LdMTf-y__F6zZGdzbKEv56jKhZw17qHKjWASKAd1TVYqCd2xo_5-Lge2_J\" style=\"margin-left: 0px; margin-top: 0px;\" width=\"402\" \/><\/span><\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">Step-3: <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">Now, fun(1) function also contains two functions.&nbsp;<\/span><\/span><\/h3>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">1. printf(&#8220;%d&#8221;, n-1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2. fun(n-1)<\/span><\/span><\/h3>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">Here n=1 and n&gt;1 hence the condition is false . So, we are not growing the tree further. Now, in order to produce the output, we have to scan the entire tree left to right. In the diagram, whenever a dot (<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">\u2022<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">) comes that means function enters into stack record and whenever printf() function comes that will produce the output. And second dot (\u2022) tells that function popped out from the stack record. Hence, this tree produces the output as 21.<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-left: 18pt; margin-right: 18pt; margin-top: 14pt; margin: 14pt 18pt 4pt; text-align: center;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"border: none; display: inline-block; height: 342px; overflow: hidden; width: 432px;\"><span style=\"font-family: courier; font-size: large;\"><img loading=\"lazy\" decoding=\"async\" height=\"342\" src=\"https:\/\/lh3.googleusercontent.com\/mNw7O8YZ_NPgQHuR0b0Xz60GkM1vMjQEDU7pdg8l41j_7F8ytpCDVvJWG65ES8wVaRphDymoWSoebqW0SkdjHSH_W3CBVsjff-wgMgHRE2x_6oGcGuhcdWTskdUkLNYxnnAqO2cE\" style=\"margin-left: 0px; margin-top: 0px;\" width=\"432\" \/><\/span><\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><\/p>\n<p><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\"><span style=\"font-family: courier; font-size: large;\">This is how recursion works when we trace it using a tree.<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><b style=\"font-weight: normal;\"><span style=\"font-family: courier; font-size: large;\"><br \/><\/span><\/b><\/p>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;\">Resources<\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">: <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; text-decoration-skip-ink: none; vertical-align: baseline; white-space: pre-wrap;\"><a href=\"https:\/\/en.wikipedia.org\/wiki\/Main_Page\" target=\"_blank\" rel=\"noopener noreferrer\">Wikipedia<\/a><\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">&nbsp;<\/span><\/span><\/h3>\n<h3 dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 4pt; margin-top: 14pt;\"><span style=\"font-family: courier; font-size: large;\"><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">If you find any problem related to this article, please comment below or contact me <\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; text-decoration-skip-ink: none; vertical-align: baseline; white-space: pre-wrap;\"><a href=\"https:\/\/www.bitsofcs.xyz\/p\/contact-me.html\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a><\/span><span style=\"background-color: transparent; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: baseline; white-space: pre-wrap;\">.<\/span><\/span><\/h3>\n<p style=\"text-align: left;\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 1. What is recursion?&nbsp; Any function(in your program) which calls itself is called a &#8216;recursive function&#8217; and this process is known as &#8216;recursion&#8216;. A recursive function solves a problem by calling a copy of itself, by working on a smaller distinct of the actual problem. The recursion step must&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/\">Read the post<span class=\"screen-reader-text\">How Recursion Works | Recursion Example in C Language | BitsOfCS<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3180","post","type-post","status-publish","format-standard","hentry","category-infinity-fitness","excerpt","zoom","full-without-featured","even","excerpt-0"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.12 (Yoast SEO v26.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How Recursion Works | Recursion Example in C Language | BitsOfCS | ManOrInfinity<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How Recursion Works | Recursion Example in C Language | BitsOfCS\" \/>\n<meta property=\"og:description\" content=\"&nbsp; 1. What is recursion?&nbsp; Any function(in your program) which calls itself is called a &#8216;recursive function&#8217; and this process is known as &#8216;recursion&#8216;. A recursive function solves a problem by calling a copy of itself, by working on a smaller distinct of the actual problem. The recursion step must&#8230;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/\" \/>\n<meta property=\"og:site_name\" content=\"ManOrInfinity\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-08T14:55:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/lh3.googleusercontent.com\/LsTMc2UpeaCdYSlZr0F842lMcyJjI-9uQ7sBj2SAJezeBQMopfIUwS5nrLR5dMZ9_h5SD2Nn1ocHKy0sgoayHJ1yy0fM9Dx6P7EqUROgGi_KBuaSZ8RVpgZAPOZf8i17gqxvH1IC\" \/>\n<meta name=\"author\" content=\"manorinfinity\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@manorinfinity\" \/>\n<meta name=\"twitter:site\" content=\"@manorinfinity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"manorinfinity\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/\"},\"author\":{\"name\":\"manorinfinity\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"headline\":\"How Recursion Works | Recursion Example in C Language | BitsOfCS\",\"datePublished\":\"2021-06-08T14:55:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/\"},\"wordCount\":703,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"image\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/lh3.googleusercontent.com\/LsTMc2UpeaCdYSlZr0F842lMcyJjI-9uQ7sBj2SAJezeBQMopfIUwS5nrLR5dMZ9_h5SD2Nn1ocHKy0sgoayHJ1yy0fM9Dx6P7EqUROgGi_KBuaSZ8RVpgZAPOZf8i17gqxvH1IC\",\"articleSection\":[\"Infinity Fitness\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/\",\"url\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/\",\"name\":\"How Recursion Works | Recursion Example in C Language | BitsOfCS | ManOrInfinity\",\"isPartOf\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/lh3.googleusercontent.com\/LsTMc2UpeaCdYSlZr0F842lMcyJjI-9uQ7sBj2SAJezeBQMopfIUwS5nrLR5dMZ9_h5SD2Nn1ocHKy0sgoayHJ1yy0fM9Dx6P7EqUROgGi_KBuaSZ8RVpgZAPOZf8i17gqxvH1IC\",\"datePublished\":\"2021-06-08T14:55:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#primaryimage\",\"url\":\"https:\/\/lh3.googleusercontent.com\/LsTMc2UpeaCdYSlZr0F842lMcyJjI-9uQ7sBj2SAJezeBQMopfIUwS5nrLR5dMZ9_h5SD2Nn1ocHKy0sgoayHJ1yy0fM9Dx6P7EqUROgGi_KBuaSZ8RVpgZAPOZf8i17gqxvH1IC\",\"contentUrl\":\"https:\/\/lh3.googleusercontent.com\/LsTMc2UpeaCdYSlZr0F842lMcyJjI-9uQ7sBj2SAJezeBQMopfIUwS5nrLR5dMZ9_h5SD2Nn1ocHKy0sgoayHJ1yy0fM9Dx6P7EqUROgGi_KBuaSZ8RVpgZAPOZf8i17gqxvH1IC\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/manorinfinity.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How Recursion Works | Recursion Example in C Language | BitsOfCS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#website\",\"url\":\"https:\/\/manorinfinity.com\/blog\/\",\"name\":\"ManOrInfinity\",\"description\":\"Thrive towards greatness\",\"publisher\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/manorinfinity.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\",\"name\":\"manorinfinity\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png\",\"contentUrl\":\"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png\",\"width\":282,\"height\":260,\"caption\":\"manorinfinity\"},\"logo\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/\"},\"description\":\"Complex Problem Solver, Outloud Thinker, An Outstanding Writer, and a very curious human being\",\"sameAs\":[\"http:\/\/manorinfinity.com\"],\"url\":\"https:\/\/manorinfinity.com\/blog\/author\/manorinfinity\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How Recursion Works | Recursion Example in C Language | BitsOfCS | ManOrInfinity","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/","og_locale":"en_US","og_type":"article","og_title":"How Recursion Works | Recursion Example in C Language | BitsOfCS","og_description":"&nbsp; 1. What is recursion?&nbsp; Any function(in your program) which calls itself is called a &#8216;recursive function&#8217; and this process is known as &#8216;recursion&#8216;. A recursive function solves a problem by calling a copy of itself, by working on a smaller distinct of the actual problem. The recursion step must&#8230;","og_url":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/","og_site_name":"ManOrInfinity","article_published_time":"2021-06-08T14:55:00+00:00","og_image":[{"url":"https:\/\/lh3.googleusercontent.com\/LsTMc2UpeaCdYSlZr0F842lMcyJjI-9uQ7sBj2SAJezeBQMopfIUwS5nrLR5dMZ9_h5SD2Nn1ocHKy0sgoayHJ1yy0fM9Dx6P7EqUROgGi_KBuaSZ8RVpgZAPOZf8i17gqxvH1IC","type":"","width":"","height":""}],"author":"manorinfinity","twitter_card":"summary_large_image","twitter_creator":"@manorinfinity","twitter_site":"@manorinfinity","twitter_misc":{"Written by":"manorinfinity","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#article","isPartOf":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/"},"author":{"name":"manorinfinity","@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"headline":"How Recursion Works | Recursion Example in C Language | BitsOfCS","datePublished":"2021-06-08T14:55:00+00:00","mainEntityOfPage":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/"},"wordCount":703,"commentCount":0,"publisher":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"image":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#primaryimage"},"thumbnailUrl":"https:\/\/lh3.googleusercontent.com\/LsTMc2UpeaCdYSlZr0F842lMcyJjI-9uQ7sBj2SAJezeBQMopfIUwS5nrLR5dMZ9_h5SD2Nn1ocHKy0sgoayHJ1yy0fM9Dx6P7EqUROgGi_KBuaSZ8RVpgZAPOZf8i17gqxvH1IC","articleSection":["Infinity Fitness"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/","url":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/","name":"How Recursion Works | Recursion Example in C Language | BitsOfCS | ManOrInfinity","isPartOf":{"@id":"https:\/\/manorinfinity.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#primaryimage"},"image":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#primaryimage"},"thumbnailUrl":"https:\/\/lh3.googleusercontent.com\/LsTMc2UpeaCdYSlZr0F842lMcyJjI-9uQ7sBj2SAJezeBQMopfIUwS5nrLR5dMZ9_h5SD2Nn1ocHKy0sgoayHJ1yy0fM9Dx6P7EqUROgGi_KBuaSZ8RVpgZAPOZf8i17gqxvH1IC","datePublished":"2021-06-08T14:55:00+00:00","breadcrumb":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#primaryimage","url":"https:\/\/lh3.googleusercontent.com\/LsTMc2UpeaCdYSlZr0F842lMcyJjI-9uQ7sBj2SAJezeBQMopfIUwS5nrLR5dMZ9_h5SD2Nn1ocHKy0sgoayHJ1yy0fM9Dx6P7EqUROgGi_KBuaSZ8RVpgZAPOZf8i17gqxvH1IC","contentUrl":"https:\/\/lh3.googleusercontent.com\/LsTMc2UpeaCdYSlZr0F842lMcyJjI-9uQ7sBj2SAJezeBQMopfIUwS5nrLR5dMZ9_h5SD2Nn1ocHKy0sgoayHJ1yy0fM9Dx6P7EqUROgGi_KBuaSZ8RVpgZAPOZf8i17gqxvH1IC"},{"@type":"BreadcrumbList","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/08\/how-recursion-works-recursion-example-in-c-language-bitsofcs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/manorinfinity.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How Recursion Works | Recursion Example in C Language | BitsOfCS"}]},{"@type":"WebSite","@id":"https:\/\/manorinfinity.com\/blog\/#website","url":"https:\/\/manorinfinity.com\/blog\/","name":"ManOrInfinity","description":"Thrive towards greatness","publisher":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/manorinfinity.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901","name":"manorinfinity","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/","url":"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png","contentUrl":"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png","width":282,"height":260,"caption":"manorinfinity"},"logo":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/"},"description":"Complex Problem Solver, Outloud Thinker, An Outstanding Writer, and a very curious human being","sameAs":["http:\/\/manorinfinity.com"],"url":"https:\/\/manorinfinity.com\/blog\/author\/manorinfinity\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts\/3180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/comments?post=3180"}],"version-history":[{"count":0,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts\/3180\/revisions"}],"wp:attachment":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/media?parent=3180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/categories?post=3180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/tags?post=3180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}