Machine-translated by Google. Questions are authored in English.
Top

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;
}

 

  • A.30
  • B.37
  • C.7
  • D.9

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.