What will be the output of the program ?
#include <stdio.h>
power(int**);
int main()
{
int a=5, *aa; /* Address of 'a' is 1000 */
aa = &a;
a = power(&aa);
printf("%d\n", a);
return 0;
}
power(int **ptr)
{
int b;
b = **ptr***ptr;
return (b);
}
Answer: B
Correct answer: 25
The expression b = **ptr***ptr; tokenises as **ptr * **ptr - the lexer taking the longest valid token at each point, so the run of asterisks splits into two dereferences, a multiplication, and two more dereferences.
ptr is a pointer to aa, which points to a, so **ptr is 5 and the product is 25. The code relies on the old implicit int return type, which was removed in C99, so it would not compile cleanly under a modern standard.
Please log in or register to report this question.