ProgrammingVery hardGATE CS · Campus placements
The Ackermann function is defined as A(0,n) = n+1, A(m,0) = A(m-1,1), and A(m,n) = A(m-1, A(m,n-1)) for m, n > 0. What is A(2,3)?
- A. 7
- B. 5
- C. 11
- D. 9
Correct answer: D. 9
A(1,n) = n+2 and A(2,n) = 2n+3, so A(2,3) = 9. The nested recursion is why such functions are a classic test of call-stack depth.
More C Programming questions
- int a[5] = {10, 20, 30, 40, 50}; int p = a + 1, q = a + 4; printf("%td %d", q - p, (p + 2)); prints what?
- void f(int a[10]) { printf("%zu", sizeof a); } Which statement about the result is correct?
- int m[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (p)[3] = m; printf("%d", ((p + 1) + 2)); prints what?
- Which statement about sizeof is correct when x is an int variable initialised to 5?
- char s[] = "hello"; printf("%zu %zu", sizeof s, strlen(s)); prints what?
- char names[] = {"ab", "cde", "f"}; What is strlen(names[0]) strlen(names[1]) + strlen(names[2])?