Data Structures & AlgorithmsModerateCognizant · Capgemini pattern

What is the value of the postfix expression 2 3 2 ^ ^ (^ means power)?

  1. A. 81
  2. B. 36
  3. C. 512
  4. D. 64

Correct answer: C. 512

Scanning: push 2, 3, 2; the first ^ pops 3 and 2 → 3² = 9; the second ^ pops 2 and 9 → 2⁹ = 512. Getting 64 means computing (2³)², which postfix order does not do.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic