void main()
{
int i=5,y=3,z=2,ans;
clrscr();
printf("%d",++i + --z + i++ + --i * ++y);
i=5,y=3,z=2;
ans=++i + --z + i++ + --i * ++y;
printf("\n%d",ans);
getch();
}
Its output is 37 and 31....
Please explain me why its different
How it works.....
Answers were Sorted based on User's Feedback
Answer / ram mohan
Ur approach may correct but I have a small dought
Plz tell me output of
Printf("", ++i + --z +i + --i * ++y) ;
@pawanjhi
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / pawanjha12
here in first statement
printf("%d",++i + --z + i++ + --i * ++y);
argument is : ++i + --z + i++ + --i * ++y.
first it will maintain stack operation like
++y (now fifth, it will execute and, y=4)(top 4)
--i (now fourth, it will execute and, i=6)
(because, last value of i were 7, once i++ were
executed, now --i will less one value in i)(top 3)
i++ (now third, it will execute and, i=6, it will
as it is, its value will for next stack value.)
(top 2)
--z (now second, it will execute and, z=1)(top 1)
++i (first it will execute and, i=6)(top 0)
now (++i + --z + i++ + --i * ++y)
(6+1+6+6*4)=(37)
it is output, say 37,for this printf("%d",++i + --z + i++
+ --i * ++y);
.................................................
Now Let me go with second statement, that is :
ans=++i + --z + i++ + --i * ++y;
here,
first of all ++y will contain the value of variable y=4
++y=4
after this, --i will less the value of variable i, say now
i = 4,
(--i=4),
after this, i++ will execute and, it will not increase the
value of variable i, right now, so value of i, say now i =
4, as it is.
after this, --z will less the value of variable z, say now
z = 1,
(--z=1)
now, ++i will increase the value of variable i.
Say i = 5.
.......................................................
now value of valiable i in memory is 5.
ans=5+1+5+5*4
ans=5+1+5+20
ans=31..........,
still if you are not getting, so come to me at
pankajace12@gmail.com
Is This Answer Correct ? | 1 Yes | 5 No |
loop1: { x=i<n?(i++):0; printf("%d",i); exit(x); continue; } Error- misplaced continue. Doubt-1.will the exit(x) be executed for all values of x 2.will this statement go out of the program.
write a profram for selection sort whats the error in it?
write the value of x and y after execution of the statements: int x=19,y; y=x++ + ++x; x++; y++;
what are the techniques for reducing the fragility of a memory bug?
Find the error (2.5*2=5) (a) X=y=z=0.5,2.0-5.75 (b) s=15;
Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a do...while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total . Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total . Use no variables other than n , k , and total .
what is run time error?
Write a C program to enter 10 integer numbers through one variable and count how many of them are even using while loop ?
Display this kind of output on screen. 1 0 1 1 0 1 3. Display this kind of output on screen. 1 1 0 1 0 1 4. Display this kind of output on screen. 1 1 0 1 0 1 5.Display this kind of output on screen. 1 2 3 4 5 6 7 8 9 10
wap for bubble sort
Declaration of Cube Guys please help me.. Is this a right way to declare cube.? If i Compile it. It Says: Cube undeclared what should i do? Please help \thanks in advanced #include<stdio.h> #include<math.h> #include<conio.h> main( ) { float x,y; while(x++<10.0) { printf("Enter Number:"); scanf("%d", &x); y = cube(x); printf("%f %f %f \n", x,pow(x,2),y); cube(x); } { float x; float y; y = x*x*x; } getch(); return (y); }
2. A student studying Information Technology at Polytechnic of Namibia is examined by coursework and written examination. Both components of assessment carry a maximum of 50 marks. The following rules are used by examiners in order to pass or fail students. a. A student must score a total of 40% or more in order to pass (total = coursework marks + examination marks) b. A total mark of 39% is moderated to 40% c. Each component must be passed with a minimum mark of 20/50. If a student scores a total of 40% or more but does not achieve the minimum mark in either component he/she is given a technical fail of 39% (this mark is not moderated to 40%) d. Grades are awarded on marks that fall into the following categories. Mark 100-70 69-60 59-50 49-40 39-0 Grade A B C D E Write a program to input the marks for both components (coursework marks out of 50 and examination marks out of 50), out put the final mark and grade after any moderation. [30]