Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on What is a output?. How will Come?. within the C and C++ forums, part of the Software Development category; main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }...
|
|||||||
|
|||
|
What is a output?. How will Come?.
main()
{ int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); } |
| The Following 5 Users Say Thank You to Golda For This Useful Post: | ||
| Sponsored Links |
|
|||
|
Re: What is a output?. How will Come?.
The values are i=0,j=0,k=1,l=3,m=1.its very simple here we r using post increments and logical and,or operations.
|
| The Following 2 Users Say Thank You to sowji_mca For This Useful Post: | ||
|
|||
|
Re: What is a output?. How will Come?.
l=0,j=0,k=1,l=3,m=1;
according to relatonal operator presedence. && , ||,! T&&T=T T&&F=f T||t=t t||f=t F||f=f |
| The Following User Says Thank You to rupesh kumar singh For This Useful Post: | ||
|
|||
|
Re: What is a output?. How will Come?.
I think may be you got the error "m is not initialized before using".....
----------------------- suresh |
| The Following 2 Users Say Thank You to psuresh1982 For This Useful Post: | ||
|
|||
|
Re: What is a output?. How will Come?.
You will not get any error.
Its just application of logical operators. Start evaluating from Left to right. All the values get post incremented. m=i++&&j++&&k++||l++; m = -1 && -1 && 0 || 2 since i, j, k ,l are post increments, they will increment after the complete statement evaluation. m = 1 && 0 || 2 m = 0 || 2 , m = 1 Here, since left side is 0, it will evaluate aven the right side also. Finally, i = 0, j = 0, k = 1, l = 3, m = 1. |
|
|||
|
Re: What is a output?. How will Come?.
main()
{ int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); } 0 0 1 3 true |
|
|||
|
It will not show any errors.
The out put of your program is : i=0;j=0;k=1;l=3;m=1(true). m=i++&&j++&&k++||l++; execution is as follows : ==> m= (i++&&j++)&&k++||l++; i=0 ; j=0 ==> m=(-1 && -1)&&k++||l++; ==> m= (1) && k++||l++; ==> m= (1 && 0)|| l++; k= 1; ==> m= (0 || 2); ==> m= 1 l=3; and (&&) operator truth table: true(1) && true(1) -------> true(1) true(1) && false(0) -------> false(0) false(0) && true(1) -------> false(0) false(0) && false(0) -------> true(1) or(||) operator truth table: true(1) || true(1) -------> true(1) true(1) || false(0) -------> true(1) false(0) || true(1) -------> true(1) false(0) || false(0) -------> false(0) ::remember these while doing the logical operator programs :: *** vishnu *** Last edited by vishnu murthy; 09-26-2007 at 06:22 AM. |
|
|||
|
Re: What is a output?. How will Come?.
Quote:
0 0 1 3 0 |
|
|||
|
Re: What is a output?. How will Come?.
ya 45545 is correct
it will check from left to right initially i=5 so for output value i it ll print as 5 for o/p --i is a prefix it will decrease and assign value to i(5-1) so for --i its 4 for o/p ++i is a prefix it will increase and assign value to i(4+1) so for ++i its 5 for i-- is post fix so it will assign previous valuue then it will decrease by 1. so o/p will be 5 only but after printing value will be 4 for i++ is post fix so it will assign previous valuue then it will increase by 1. so o/p will be 4 only but after printing value will be 5 so finally value of i=5 |
|
|||
|
Quote:
00000001 || 00000011=00000001 Nice job rupesh |
|
|||
|
Re: What is a output?. How will Come?.
the o/p of this program is 00131
in given expression (m=i++&&j++&&k++||l++) operater play an imp role i.e. we will first evaluted incre. op. that has higher predency after that we will evaluted logical AND op(&&) and after that logical OR(||) op.and at the end as.op(=) will be evaluted . note that it is a logical exp. so m have value either 1 or 0. while in this exp it is true so has 1 as o/p and the value of i,j,k and l is incremented when write exp , so it print these incremented value by 1 so these value become 0,0,1,and 3 and the value of m is evaluted in exp ,1 dilip agrawal mca indore mp |
|
|||
|
Re: What is a output?. How will Come?.
00131 is the answer.
m=i++ && j++ && k++ || l++; let us leave all the postfix increments because they will change the values only in the next statement of their respective variables. so m=i && j&& k|| l -1 && -1=0 0 && 0=0 0 || 2=1 so m is 1. this statement is over then all the variables will be incremented by 1 because of that postfix increments. so output is 00131 |
|
|||
|
i=0,j=0,k=1,l=3,m=0
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| First output value is getting overwritten by second output | Geek_Guest | QTP | 2 | 01-05-2008 04:40 AM |
| Input and output | AnnieL4864 | VB.NET | 1 | 11-20-2007 05:12 AM |
| How many Classes in output | JobHelper | Java | 7 | 06-12-2007 04:14 AM |
| Output Value | bharathi_ark | Testing Issues | 5 | 12-27-2006 07:13 AM |
| Output Functions | RyanJames | C and C++ | 5 | 12-20-2006 03:10 AM |