+ 2

Any one tell me pre-increment of array???How the value of x became 10???

*🎙️Predict the output of the following code segment:* int main() { int array[10] = {3, 0, 8, 1, 12, 8, 9, 2, 13, 10}; int x, y, z; x = ++array[2]; y = array[2]++; z = array[x++]; printf("%d %d %d", x, y, z); return 0; } 🎯a. 10 9 10

20th Sep 2020, 6:12 AM
ASHA NIKAM
ASHA NIKAM - avatar
3 Respuestas
+ 1
x increases at array[x++]. Before that, x is initialized with ++array[2] which is 9.
20th Sep 2020, 6:15 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 4
Array index start from zero here array[2] index value is 8 and In expression x=++array[2] =++8 ; here 8 will increase by 1 so 9 will assign to x x=9 After that y=array[2] assigned to y and which value 9 becoz in x value of 2nd index is incresed After next line z=array[x++]; x was 9 so z=array[9] which value is 10 So z =10 and z=array[x++] here you used Post increment after assign value 10 it will increase becoz post inc increment after calculate expression so present value of x will be 10 and c is procedural language so now x is changed so we will use present value of x So final Output is x=10 y=9 z=10
20th Sep 2020, 6:21 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Thanks
21st May 2023, 2:08 PM
Abhishek Tiwari
Abhishek Tiwari - avatar