|
| makan007 (57) | |||
How to begin working for the answer inthis qns? It looks messy...
| |||
Last edited on | |||
| helios (6075) | |
| What? | |
| makan007 (57) | |
| I know this code includes bitwise but i was confuse whether to use x = 30 or 1, y = 20 or 2, z = 10 or 3? | |
Last edited on | |
| mcleano (733) | |
| You realise that line 4 and 23 need to be the same right? | |
| makan007 (57) | |
| Can elaborate further? Line 28 the answer is 4? | |
| helios (6075) | ||
I still don't understand what OP is asking, though. | ||
| makan007 (57) | |
| I know that Line 12: 1 + 2 + 3 + 4 = 10 I know that Line 16 = 2 (10/2 = 010 = 2) How about Line 10 & Line 14? | |
| mcleano (733) | ||
Ok my mistake (although I did check my book to make sure you were correct... yes I doubted Helios!) It does say though that: " When creating a function that has default argument values, the default values must be specified only once, and this must happen the first time the function is declared within the file. " ... and then goes on to say the compiler will display an error if you try to do so in both prototype and definition. Line 10: function is called with arguments, 4 and 5. Variable x is assigned 4 as it appears first, variable y is assigned 5 as it appears second, variable z is assigned 10 as no given value is specified. x + y + z + staticVar() 4 + 5 + 10 + (2+2) = 23 Line 14: staticVar() contains a static variable which is initially assigned a value of 2. It is then gievn the addition of 2 and returned. By the time the program reached line 14, staticVar() has been called twice - line 14 being third. Therefore: x = 2 x +=2 // first call x = 4 x +=2 // second call x = 6 x+=2 // third call x = 8 | ||
Last edited on | ||
This topic is archived - New replies not allowed.
