WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW
IT COME ..
#include<stdio.h>
#include<conio.h>
void main()
{
int k=20;
printf("%d%d%d%d",k,k++,++k,k);
getch();
}
Answers were Sorted based on User's Feedback
22 21 21 20 THIS WILL THE OUTPUT..
this is merely an STACK operation.... here we have 4
parameters.. so the four parameters will be pushed inside
the stack one by one... as
TOP : k
++k
k++
BOTTOM : k
so the expressions will be evaluated from the top.. and thus
the answer....
thank u
| Is This Answer Correct ? | 9 Yes | 3 No |
Answer / mohamed ali
THE ANSWER IS
20 20 22 22
YOU HAVE THE 1ST 20 AS IT'S THE INITIAL VALUE
THEN YOU HAVE K++ .... HERE WE HAVE THE SAME VALUE OF K THEN
IT WILL BE INCREMENTED BY ONE .... SO YOU HAVE THE 2ND 20
AND THEN K WILL BE 21
THE THIRD YOU HAVE ++K .... WHICH MEANS THAT YOU WILL
INCREMENT THEN TYPE THE VALUE AND SINCE YOU HAVE NOW K=21
FROM PREVIOUS STEP (K++) SO THIS VALUE WILL BE INCREMENTED
BY ONE (K = 22 ) SO YOU HAVE THE THIRD VALUE 22
THEN YOU HAVE A SINGLE K WITH NO OPERATIONS SO ANOTHER 22
IF SOMEONE SEES THAT I'M WRONG PLZ CORRECT MY VIEW
THANKS
| Is This Answer Correct ? | 8 Yes | 5 No |
Answer / prats
but when we compile this code in editor it shows the output
22 21 21 20 .
whts wrong then ?
| Is This Answer Correct ? | 5 Yes | 2 No |
Answer / pratik
i am agree with yognesh , ,
when u compile this is C it gives 22 21 21 20 . .
check it out ..
| Is This Answer Correct ? | 3 Yes | 2 No |
Answer / rajadurai thangaraj
22 21 22 22
stack execution:-
4 ->printf k now k=22
3 ->printf 21 k=k+1 now k=22, k of 1&2 also 22
2 ->k=k+1 printf k now k=21, k of 1 also 21
1 ->printf k now k=20
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / ashish
20212120 is the write answer because there is no space between
specified data type %d
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / anand
The answer should be 22212120
Arguments passed to the printf statement would get executed
from the right to left..
1. k = 20
2. ++k = 21 (Pre Increment)
3. k++ = 21 (Post Increment(k value now is 22))
4. k = 22
Thus the output : 22212120
| Is This Answer Correct ? | 1 Yes | 1 No |
What does the && operator do in a program code?
Suppose we have a table name EMP as below. We want to perform a operation in which, I want to change name ‘SMITH’ from as ‘SMITH JAIN’. Also I want to change the name of the column from ENAME to E_NAME. EMPNO ENAME JOB MGR HIREDATE SAL 7369 SMITH Coder 7902 17-DEC-80 800 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 7521 WARD SALESMAN 7698 22-FEB-81 1250
Snake Game: This is normal snake game which you can find in most of the mobiles. You can develop it in Java, C/C++, C# or what ever language you know.
7 Answers Accenture, Gridco, IBM, Kevin IT, TCS, Vimukti Technologies,
What is extern c used for?
What is hash table in c?
Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 1. Print only the alphabets . If in upper case print in lower case vice versa.
Is c an object oriented programming language?
dibakar & vekatesh..uttejana here..abt ur reply for in place reversal of linked list..wats p stands for there?
Can we assign integer value to char in c?
I heard that you have to include stdio.h before calling printf. Why?
What are pointers? What are different types of pointers?
What is Conio.h ?