Programming logic puzzle
1,264.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; }
ERROR
i+++ at line 20 is not executable.
pardon me if I am wrong.
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.
Your Answer
More puzzles to try-
Can You?
I make babies look smart, I make you look dumb, I make your phone work, I stop you from freezing ...Read More »Place the Balls
Can you place three balls such that the equation shown in the picture holds true?Read More »Typical Image Puzzle
What do you see in the image belowRead More »You cannot hold but it is yours
What you cannot hold but it is yours?Read More »Fair soccer championship
The games played in the soccer world championship form a binary tree, where only the winner of each game moves ...Read More »Minimum chances to draw a pair of same color
Your sock drawer contains ten pairs of white socks and ten pairs of black socks. If you’re only allowed to ...Read More »Typewritter Riddle
Customer services at Puzzlefry headquarters received the following letter yesterday. Our top puzzle solvers were able to determine the meaning ...Read More »Fireman, policeman and a doctor brain teaser
After looking for his long lost brother that he has never met before, Justin is able to find his brother’s ...Read More »Mysterious Island
A man is surviving on an island along with his friend. They have been starving for four days for food. ...Read More »100 doors
There are 100 doors, all closed. In a nearby cage are 100 monkeys. The first monkey is let out, and ...Read More »How many squares would there be in total on chess board
If you were to construct a 8 x 8 checkered square (i.e., a 8 x 8 chess board). How many ...Read More »Burning ropes to measure time
Warm-up: You are given a box of matches and a piece of rope. The rope burns at the rate of ...Read More »How could you remove the coin without taking out the cork or breaking the bottle?
If you were to put a coin into an empty bottle and then insert a cork into the neck, how ...Read More »Age ageing puzzle from ages
Gordon is twice as old as Tony was when Gordon was as old as Tony is now. The combined age ...Read More »Cutting the shape to get most pieces
Here is the picture of cross. You have to make two straight cuts across it. How do you cut it ...Read More »Odd One Riddle
Which is the odd one out: curtain, door, veil, shutter, screenRead More »How is this possible?
A man and his boss have the same parents, but are not siblings. How is this possible?Read More »Find 6 hidden word in the newly painted room puzzle
Find 6 hidden word in the newly painted roomRead More »How can this happen?
There were two grandmothers and their two granddaughters. There were two husbands and their two wives. There were two fathers ...Read More »ABCD to DCBA riddle
ABCD × E = DCBA (Replace letters with digits and have the sum be true. A,B,C,D and E are all ...Read More »
Accenture Interview PuzzlesAdobe Interview PuzzlesAge RiddleAkbar Birbal PuzzlesAlgorithm PuzzlesAlphabet riddleAmazon Interview PuzzlesAnalytical MathematicsAptitude PuzzleBank PuzzlesBetting PuzzlesBrain TeasersCalendar PuzzlesCards PuzzlesChess Board PuzzleChess PuzzlesChristmas Puzzlecipher PuzzleCivil Services PuzzleClock time puzzleCognizant Interview PuzzlesCoins PuzzleComputational PuzzleconundrumCoronavirus PuzzleCoupondunia Interview PuzzleCritical Thinking Puzzledata analyticsData Structure Interview QuestionsDecode PuzzleDetective PuzzlesDice PuzzleDictionary Riddlesdifficult riddleEasy Math puzzlesEasy puzzlesEinstein puzzleEnglish RiddleFamily Tree Puzzlefamous puzzleFill in the blanks riddlesFinding Killer RiddlesFlipkart interview puzzlesFunny RiddlesGeneral KnowledgeGeographical PuzzleGoogle Code Jam 2014Google Interview PuzzlesGRE PuzzleHard Puzzle