Geeks Talk

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.

What is a output?. How will Come?.

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); }...

Go Back   Geeks Talk > Software Development > C and C++
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 09-17-2007
Contributing Member
 
Join Date: Sep 2007
Location: India
Posts: 34
Thanks: 16
Thanked 5 Times in 1 Post
Golda is on a distinguished road
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);
}
Reply With Quote
The Following 5 Users Say Thank You to Golda For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 09-18-2007
Junior Member
 
Join Date: Jul 2007
Location: Banglore
Posts: 24
Thanks: 6
Thanked 4 Times in 3 Posts
sowji_mca is on a distinguished road
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.
Reply With Quote
The Following 2 Users Say Thank You to sowji_mca For This Useful Post:
  #3 (permalink)  
Old 09-18-2007
Contributing Member
 
Join Date: Sep 2007
Posts: 39
Thanks: 1
Thanked 3 Times in 3 Posts
ssuvi is on a distinguished road
Re: What is a output?. How will Come?.

I think m=0
Reply With Quote
The Following User Says Thank You to ssuvi For This Useful Post:
  #4 (permalink)  
Old 09-20-2007
Junior Member
 
Join Date: Sep 2007
Location: nodia
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
rupesh kumar singh is on a distinguished road
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
Reply With Quote
The Following User Says Thank You to rupesh kumar singh For This Useful Post:
  #5 (permalink)  
Old 09-21-2007
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,016
Thanks: 0
Thanked 91 Times in 72 Posts
psuresh1982 will become famous soon enough
Re: What is a output?. How will Come?.

I think may be you got the error "m is not initialized before using".....

-----------------------
suresh
Reply With Quote
The Following 2 Users Say Thank You to psuresh1982 For This Useful Post:
  #6 (permalink)  
Old 09-24-2007
Junior Member
 
Join Date: Sep 2007
Location: Bangalore
Posts: 1
Thanks: 0
Thanked 2 Times in 1 Post
p.veena26 is on a distinguished road
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.
Reply With Quote
The Following 2 Users Say Thank You to p.veena26 For This Useful Post:
  #7 (permalink)  
Old 09-25-2007
Junior Member
 
Join Date: Sep 2007
Posts: 1
Thanks: 0
Thanked 2 Times in 1 Post
jerroldneal is on a distinguished road
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
Reply With Quote
The Following 2 Users Say Thank You to jerroldneal For This Useful Post:
  #8 (permalink)  
Old 09-26-2007
Junior Member
 
Join Date: Jul 2007
Location: hyderabad
Posts: 1
Thanks: 0
Thanked 2 Times in 1 Post
vishnu murthy is on a distinguished road
Post Re: What is a output?. How will Come?.

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.
Reply With Quote
The Following 2 Users Say Thank You to vishnu murthy For This Useful Post:
  #9 (permalink)  
Old 10-01-2007
Junior Member
 
Join Date: Sep 2007
Location: tuticorin
Posts: 1
Thanks: 0
Thanked 2 Times in 1 Post
antonysophia is on a distinguished road
Re: What is a output?. How will Come?.

Quote:
Originally Posted by Golda View Post
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);
}
ans:
0 0 1 3 0
Reply With Quote
The Following 2 Users Say Thank You to antonysophia For This Useful Post:
  #10 (permalink)  
Old 10-04-2007
Contributing Member
 
Join Date: Sep 2007
Location: India
Posts: 34
Thanks: 16
Thanked 5 Times in 1 Post
Golda is on a distinguished road
Re: What is a output?. How will Come?.

main()
{
int i=5;
printf("%d%d%d%d%d",i++, i--, ++i, --i,i);
}
I got the output 45545. How it will come?...
Reply With Quote
  #11 (permalink)  
Old 10-04-2007
Contributing Member
 
Join Date: Aug 2007
Posts: 70
Thanks: 12
Thanked 10 Times in 8 Posts
raj1402 is on a distinguished road
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
Reply With Quote
The Following 2 Users Say Thank You to raj1402 For This Useful Post:
  #12 (permalink)  
Old 10-06-2007
Contributing Member
 
Join Date: Sep 2007
Location: India
Posts: 34
Thanks: 16
Thanked 5 Times in 1 Post
Golda is on a distinguished road
Re: What is a output?. How will Come?.

what about this?
void main()
{
unsigned giveit=-1;
int gotit;
printf("%u ",++giveit);
printf("%u ",gotit=-giveit);
}
Reply With Quote
  #13 (permalink)  
Old 10-09-2007
Contributing Member
 
Join Date: Aug 2007
Posts: 70
Thanks: 12
Thanked 10 Times in 8 Posts
raj1402 is on a distinguished road
Re: What is a output?. How will Come?.

hmm no idea abt unsigned int

Last edited by raj1402; 10-09-2007 at 01:53 AM.
Reply With Quote
  #14 (permalink)  
Old 10-09-2007
Junior Member
 
Join Date: Sep 2007
Location: Pune
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
riznisp is on a distinguished road
Thumbs up Re: What is a output?. How will Come?.

Quote:
Originally Posted by rupesh kumar singh View Post
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
A good explaination with truth values m=1 cause at bit level
00000001 || 00000011=00000001
Nice job rupesh
Reply With Quote
  #15 (permalink)  
Old 10-09-2007
Contributing Member
 
Join Date: Aug 2007
Posts: 70
Thanks: 12
Thanked 10 Times in 8 Posts
raj1402 is on a distinguished road
Re: What is a output?. How will Come?.

i think u have declared giveit as unsigned and assigned "-1"
Reply With Quote
The Following User Says Thank You to raj1402 For This Useful Post:
  #16 (permalink)  
Old 10-12-2007
Contributing Member
 
Join Date: Sep 2007
Location: India
Posts: 34
Thanks: 16
Thanked 5 Times in 1 Post
Golda is on a distinguished road
Re: What is a output?. How will Come?.

Ya i declared giveit as unsigned and assigned -1 only
Reply With Quote
  #17 (permalink)  
Old 10-16-2007
Junior Member
 
Join Date: Oct 2007
Location: indore
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
dilip agrawal is on a distinguished road
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
Reply With Quote
  #18 (permalink)  
Old 11-19-2007
Junior Member
 
Join Date: Oct 2007
Location: chennai
Posts: 5
Thanks: 1
Thanked 1 Time in 1 Post
r.praveenkumar is on a distinguished road
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
Reply With Quote
  #19 (permalink)  
Old 11-22-2007
Junior Member
 
Join Date: Nov 2007
Location: India
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
azim42003 is on a distinguished road
Re: What is a output?. How will Come?.

out put vil b
-1,-1,0,2,1
Reply With Quote
  #20 (permalink)  
Old 11-27-2007
Contributing Member
 
Join Date: Oct 2007
Location: trichy
Posts: 92
Thanks: 2
Thanked 13 Times in 9 Posts
sarathi trichy is on a distinguished road
Smile Re: What is a output?. How will Come?.

Quote:
Originally Posted by Golda View Post
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);
}
i=0,j=0,k=1,l=3,m=0
Reply With Quote
Reply

  Geeks Talk > Software Development > C and C++

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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


All times are GMT -4. The time now is 04:01 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved