# Programming logic puzzle

1,100.4K Views

What will be the output of the following program?

```int main() {

union {

int i;

int j;

void f() {

printf("i=%d, j=%d\n", i, j);

}

};

i = 3;

j = i+++ ++i;

f();

return 0;

}

```
SherlockHolmes Expert Asked on 2nd August 2016 in

Error message….

dyj Expert Answered on 5th August 2016.

ERROR
i+++ at line 20 is not executable.
pardon me if I am wrong.

Shubham Patra Guru Answered on 15th August 2016.

i = 5, j = 8

This statement,: j = i+++ ++, i is actually

j = i++ + ++i;

i = 3 at first, then starting from left we look at i++, so the expression takes the values as 3 because i++ is a post-increment and afterwards increments i to 4. Then it looks at the other part of the expression which is ++i so for this it does a pre-increment and i becomes 5 and then 3 + 5 is added together and assigned to j.

• ## More puzzles to try-

• ### only Fresh

It is the only vegetable or fruit that is never sold frozen, canned, processed, cooked, or in any other form ...Read More »
• ### Water measuring riddle

Using only a 5-gallon bucket and a 3-gallon bucket, put exactly four gallons of water in the 5-gallon bucket. (Assume ...Read More »
• ### How will you write 6 times?

Assume 9 is twice 5; how will you write 6 times 5 in the same system of notation?Read More »
• ### A Safe Place

Frank leaves home.  When he tries to return, a man wearing a mask blocks his path. 1.) What is Frank ...Read More »
• ### Vegetable on boat riddle

There is a vegetable that is very unpopular on the boat. Can you name it?Read More »
• ### TIME PUZZLES

Fifty minutes ago if it was four times as many minutes past three o’clock, how many minutes is it until ...Read More »
• ### Cross the Gate

You need to complete the maze by entering from the entrance marked below in the figure near the yellow circle, ...Read More »
• ### Game of Cards

13 decks of cards have been mixed. What is the minimum number of cards that must be taken out from ...Read More »
• ### Feared and hated by many riddle

Respected by few, Feared and hated by many. Mistress of the entire universal reason, Master in the art of numbers. ...Read More »
• ### Is not a Mermaid riddle

What has beautiful hair, a pretty face, two arms, a fish’s tail, looks like a mermaid, but is not a ...Read More »
• ### Globe Walker puzzle

How many points are there on the globe where, by walking one mile south, then one mile east and then ...Read More »
• ### Who killed Mr. John

Mr. John lives in a mansion. He is very rich. He is so rich that he has a maid, a ...Read More »
• ### English Word with all Vowels

There are five vowels (a, e, i, o, u) in the English language. Can you tell us a word that ...Read More »
• ### Who am I?

If you say my name, I’ll no longer exist. What am I?Read More »

• ### Taller than you riddle

Tell the word used to greet, and also used to describe something taller than you ?Read More »
• ### Song wins \$1,000 riddle

A poor woman and a rich woman are talking about music. The poor woman says she has studied music and ...Read More »
• ### How is this situation explained?

A boy and his father are caught in a traffic accident, and the father dies. Immediately the boy is rushed ...Read More »
• ### How will they split the loot?

Five pirates stole a treasure – exactly hundred gold coins. Pirates have a special way of dividing their loot: The ...Read More »
• ### Sequence Puzzle

There is this one man who killed his mother, was born before his father and married over 100 women without ...Read More »