43 43 votes What is the value printed by the following C program? #include<stdio.h> int f(int *a, int n) { if (n <= 0) return 0; else if (*a % 2 == 0) return *a+f(a+1, n-1); else return *a - f(a+1, n-1); } int main() { int a[] = {12, 7, 13, 4, 11, 6}; printf("%d", f(a, 6)); return 0; } $-9$ $5$ $15$ $19$ Algorithms gatecse-2010 algorithms recursion identify-function normal + – go_editor 17.1k views answer comment Share Follow Print See all 2 Comments 2 2 Comments reply krish__ commented Nov 22, 2017 reply Follow flag @kenzou, The program won't compile with parenthesis used in the initializer. Please change it to "{ }" 1 1 replyShare Arjun commented Aug 25, 2022 reply Follow flag Fixed now. 0 0 replyShare Please log in or register to add a comment.
Best answer 37 37 votes Suppose $int$ array takes $4$ bytes for each element and stored at base address $100$. Follow below image. Red color shows the return value. So, $15$ is the answer. Correct Answer: $C$ Rajesh Pradhan answered Nov 11, 2016 • edited Nov 6, 2021 by Kiyoshi Rajesh Pradhan comment Share Follow See all 8 Comments 8 8 Comments reply Show 5 previous comments Arjun commented Aug 25, 2022 reply Follow flag Does that matter here? 0 0 replyShare Thadymademe commented Aug 25, 2022 reply Follow flag No @Arjun Sir but in general it matters right like of a question if asked that what is the size of int data type in C language ?? 0 0 replyShare Abhrajyoti00 commented Dec 16, 2022 reply Follow flag @abir_banerjee Such a question will never be asked for sure. 0 0 replyShare Please log in or register to add a comment.
39 39 votes It will print $12 + ( 7 - (13 - (4 + (11 - ( 6 + 0)))))$ $\quad = 12 + (7 - (13 - ( 4 + ( 11 -6)))))$ $\quad= 12 + 7 - 13 + 9$ $\quad= 15$ gatecse answered Oct 1, 2014 gatecse comment Share Follow See all 2 Comments 2 2 Comments reply pavansan commented Jan 4, 2025 reply Follow flag @gatecse sir can u pls tell me how this addition and subtraction works here i am not getting 0 0 replyShare Amjad. commented Apr 15, 2025 reply Follow flag @pavansan add or sub which are present inside the parathesis, do this layer by layereg : 6+0 is done first and then 11 - 6 and then ... 0 0 replyShare Please log in or register to add a comment.
18 18 votes Answer : Option C) 15 tvkkk answered Jul 9, 2017 tvkkk comment Share Follow See 1 comment 1 1 comment reply indra kumar sahu commented Oct 18, 2020 reply Follow flag nice explaination 0 0 replyShare Please log in or register to add a comment.
5 5 votes it is C. 15. Gate Keeda answered Oct 1, 2014 Gate Keeda comment Share Follow 0 reply Please log in or register to add a comment.
1 1 vote Here is the explanation !! ritiksri8 answered May 10, 2024 ritiksri8 comment Share Follow 0 reply Please log in or register to add a comment.