Discussion
What will be the output of the program ?
#include <stdio.h>
int main()
{
int i=3, *j, k;
j = &i;
printf("%d\n", i**j*i+*j);
return 0;
}
Answer: A
Correct answer: 30
The expression i**j*i+*j looks alarming but tokenises unambiguously as i * (*j) * i + (*j): the lexer takes the longest valid token at each point, so ** becomes * followed by unary *.
With i = 3 and *j = 3:
\[ 3 \times 3 \times 3 + 3 = 27 + 3 = 30 \]
Multiplication binds tighter than addition, so no parentheses are needed to get this grouping.
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