Discussion
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.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development