hello, can someone explain me how this printf inside the function works?

#include<stdio.h>
#define SIZE 10
void function(int [],int);
int main()
{
		int a[SIZE]={32,27,64,18,95,14,90,70,60,37};
		function(a,SIZE);
		return 0;
		}
		void function(int b[],int size)
		{
			if(size>0){
				function(&b[1],size-1);
				printf("%d  ",b[0]);
			}
			
		}

Edited 5 Years Ago by gynmd: n/a

it seems when program comes to function(&b[1],size-1) part
it calls the function again and then the same
how and when does the printf() work when the function is calling itself ?

Each time the function calls itself, it calls itself with a slice of the array. The first element is sliced off, which means b[1] becomes b[0] for the next call. Repeating that process while decrementing size until size is 0 produces the recursive equivalent of a reverse traversal loop:

for (int i = size - 1; i >= 0; i--)
    printf("%d  ",b[0]);

the function calls itself before reaching printf what I don't understand is how printf runs

@Utsav,after calling function(b[1],0),the code completes all calling functions from function (b[1],1) to function(b[1],9) by writing printf part of if clause.

Edited 5 Years Ago by gynmd: n/a

This question has already been answered. Start a new discussion instead.