0 votes 0 votes #include<stdio.h> int reverse(int); int main() { int num=4; reverse(num); return 0; } int reverse(num) { if(num==0) return 0; else printf("%d",num); reverse(num--); } What is the output ? Programming in C programming-in-c output + – junaid ahmad asked Dec 20, 2017 edited Dec 20, 2017 by joshi_nitish junaid ahmad 877 views answer comment Share Follow See all 17 Comments See all 17 17 Comments reply Ashwin Kulkarni commented Dec 20, 2017 reply Follow Share It will give compilation error 1) It will treat int reverse (num) as new function declaration and give error (because 2) I think error at else . 0 votes 0 votes Akash Mittal commented Dec 20, 2017 reply Follow Share segmentation fault will occur because of post increment while calling function. 0 votes 0 votes Pawan Kumar 2 commented Dec 20, 2017 reply Follow Share int reverse(num) { if(num==0); return 0; else printf("%d",num); reverse(num--); } Case 1: error at else (without if) Case 2: if(num==0) then infinite times looping because of post decrement 0 votes 0 votes junaid ahmad commented Dec 20, 2017 reply Follow Share @Akash Mittal why do you think it give segmentation fault,i think when we do post ,it wil simply decrement the value at memory location where num is stored,how is it going out of bound. 0 votes 0 votes junaid ahmad commented Dec 20, 2017 reply Follow Share @Pawan Kumar how it can run infinite times. 0 votes 0 votes Akash Mittal commented Dec 20, 2017 reply Follow Share @ junaid ahmad "4" will be printed infinite times which leads to access memory which doesn't belong to us and leads to stack overflow. Thus, segmentation fault will occur. 1 votes 1 votes Pawan Kumar 2 commented Dec 20, 2017 reply Follow Share because of post increment , first 4 will be taken into consideration then decremented but before 4 could be decremented it will keep on taking reverse(4)....... had it been (--4) ans would be 4321 0 votes 0 votes joshi_nitish commented Dec 20, 2017 reply Follow Share @junaid f(num--) it is post decrement original value will be passed to function and after that it will be decremented in local scope. 1 votes 1 votes junaid ahmad commented Dec 20, 2017 reply Follow Share @joshi ,so it will print 4,3,2,1 ? 0 votes 0 votes joshi_nitish commented Dec 20, 2017 reply Follow Share it will keep on printing 4,4,4,4,4,4............ 0 votes 0 votes Ashwin Kulkarni commented Dec 20, 2017 reply Follow Share @nitish this program won't run! error at int reverse (num). 0 votes 0 votes saxena0612 commented Dec 20, 2017 reply Follow Share There are lost of error in this program 2 main declarations semicolon after if etc. Talking about core working due to post decrement this is not going to stop and hence will give segmentation fault or overflow. 0 votes 0 votes joshi_nitish commented Dec 20, 2017 reply Follow Share though this program will not run, but it will compile successfully. 0 votes 0 votes Anu007 commented Dec 20, 2017 reply Follow Share yes now it run correctly #include<stdio.h> int main() { int num=4; reverse(num); return 0; } int reverse(num) { if(num==0) return 0; else printf("%d",num); reverse(num--); } 0 votes 0 votes Ashwin Kulkarni commented Dec 20, 2017 reply Follow Share No it cant compile successfully! It searches for Int reverse (int) 0 votes 0 votes Anu007 commented Dec 20, 2017 reply Follow Share see my comment 0 votes 0 votes Ashwin Kulkarni commented Dec 20, 2017 reply Follow Share Yes now it will show runtime error I didn’t see edited code :p 0 votes 0 votes Please log in or register to add a comment.