473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Have a Prob in finding the output

I write the code....
Expand|Select|Wrap|Line Numbers
  1. void main()
  2. {
  3. int i=-3,j=2,k=0,m;
  4. m=++j&&++i||++k;
  5. printf("%d%d%d%d",i,j,k,m);
  6. getch();
  7. }
  8.  
THE out put of this program is -2301
plz explain why -2301 comes.....
thank you
May 14 '10 #1
6 1412
donbock
2,426 Expert 2GB
First let me ask you: What do you think are the values of i, j, k, and m immediately before the printf statement?

You will learn this better if you struggle through on your own a little.
May 14 '10 #2
@donbock
according to me the value of i =-3 there is in increment in i in the expression so the value of i is incremented that means i=-2 there is an increment in j also so that the value of j is incremented to 3 but the value of k remains as it is it should be incremented because in the expression its incremented...
& the value of m is 1 by using the truth table relation........
that is my thinking about taking this program...
but the thing is we use increment operator in the expression, is it actually change the value of i at their address when i print the valu i for j & k onwards.?
May 15 '10 #3
weaknessforcats
9,208 Expert Mod 8TB
When you have an OR, the compiler can evaluate the expression until it can determine whethere it is true or false. Then it can stop evaluation. In your case, the expression is true always because the values in i and j are always true. The makes AND of i an j always true and this makes the OR always true.

Therefore, there is no need to evaluate k.

Worse, the order of evaluation depends on the compiler. You may find this works as you expect on another compiler if it evaluates all lf the variables first and then applies the logical operators. However, the compiler is free to evaluate the variables in an expression in any order.
May 15 '10 #4
newb16
687 512MB
However, the compiler is free to evaluate the variables in an expression in any order.
Afaik in the case of logical || and && the compiler has no choice - it evaluates the left expression first, and if it is true (false), doesn't evaluate the right one.
E.g.
dosomething() || exit();
May 15 '10 #5
@newb16
tnx i got the point & now i understand how this ans comes
May 16 '10 #6
donbock
2,426 Expert 2GB
You should read up on short-circuit evaluation.
May 17 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: supratik chakraborty | last post by:
I am not getting any output for the following lines of code... while(line_buf>>value) { cout<<"Pushing a value in the list"<<endl; line_list.push_front(value);//add the value to the list...
1
by: Lisa | last post by:
I need to apply the HTML formatting tags and the French accented characters in a XML document. The XML is generated from a database that has HTML tags and French accented characters in the records....
4
by: nichas | last post by:
the code is ... int main(void){ static int a={1,2,3,4,5}; static int *p={a,a+1,a+2,a+3,a+4}; int i; for(i=0;i<5;i++){ printf("%u\n",a+i);} printf("\n%u\t%u\t%d",p,*p,*(*p)); return 0; } Now...
0
by: Top Gun | last post by:
I have been finding difficulty in locating decent, in-depth information on a standard matter in the IT world... STRING FORMATTING. Particuarlly as it relates to C# (or .NET). The books I have give...
1
by: tkaleb | last post by:
I have to create output file in a text, MS Access, MS Excel and .dbf format from C# Win/ADO.NET application. Data are collected in DataSet and there is no problem to make text file. However, I have...
2
by: Hawk | last post by:
I have a custom menu control that I am creating using C#. I am rendering HTML from a StringBuilder in my control to add the needed JavaScript to the HTML output. I need to have the JavaScript...
32
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input...
2
by: Tarren | last post by:
Hi: Is it possible (examples?) to have iis insert content into every page that is served up for a given app? I am wanting to put heartbeat data into each page on my intranet site. Thanks
1
by: mahajanrahuld | last post by:
hi i written the script for database connectivity with ms access , connection is proper but the script can not display any reslut on browser ..... code is ..... #!usr/bin/perl use...
1
by: JCMcAbee | last post by:
Hello. Working in Access 2003. I have seen posts similar to this, but I think my question is a little different. My knowledge is VERY basic, so I hope I will explain this clearly. I have a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.