Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h>..

Answer / pratik.nikam3112

answer is

22 21 21 20

Is This Answer Correct ?    38 Yes 8 No

WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h>..

Answer / balug

22 21 21 20

Is This Answer Correct ?    8 Yes 2 No

WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h>..

Answer / vignesh1988i

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

WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h>..

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

WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h>..

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

WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h>..

Answer / sunil

answer is

22 21 21 20

printf .. executes from left hand side..


so first ..

printf("$d %d %d %d",k,K++,++k,k);

4.last k ie; 20
3.++k (pre) : 21
2.k++ (post) : 21 and then increamented
1.k : 22

answer is : 22 21 21 20

Is This Answer Correct ?    3 Yes 1 No

WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h>..

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

WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h>..

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

WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h>..

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

WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h>..

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

Post New Answer

More C Interview Questions

what is a constant pointer in C

0 Answers  


FILE PROGRAMMING

0 Answers   Wipro,


How will you allocate memory to a double pointer ?

2 Answers  


Why do we use namespace feature?

0 Answers  


Write a program with dynamically allocation of variable.

0 Answers   Atos Origin,


When should a type cast not be used?

0 Answers  


How to avoid structure padding in C?

8 Answers   Tech Mahindra,


Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.

0 Answers   Aspiring Minds,


What is cohesion and coupling in c?

0 Answers  


write a program that eliminates the value of mathematical constant e by using the formula e=1+1/1!+1/2!+1/3!+

1 Answers   Reliance,


declare afunction pointer to int printf(char *)?

1 Answers   HCL,


what are the uses of structure?

7 Answers   HCL,


Categories