473,397 Members | 2,084 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,397 software developers and data experts.

Hi a strange code ....

Hi ..

Well I have a strange code here which i am not usre have a clear
understanding.

I have compiled it on turbo C++3.0 compiler and Devc++ compiler ..
here is the code ..
int main(void)
{
int i=0;,j=10,k=20;
if(i,j,k)
printf("welcome");
else
printf(" Home");
return 0;
}

the output is welcome.
What i found out after a little experimenting is i,j,k taking
individually as expressions are evaluated .. where as k is used to
evaluate the if condition ....

Let me know if iam wrong ..

Aug 29 '06 #1
4 1396
dh**********@gmail.com wrote:
Hi ..

Well I have a strange code here which i am not usre have a clear
understanding.

I have compiled it on turbo C++3.0 compiler and Devc++ compiler ..
here is the code ..
int main(void)
{
int i=0;,j=10,k=20;
if(i,j,k)
printf("welcome");
else
printf(" Home");
return 0;
}

the output is welcome.
What i found out after a little experimenting is i,j,k taking
individually as expressions are evaluated .. where as k is used to
evaluate the if condition ....

Let me know if iam wrong ..
<
I think it is correct... the result of (i,j,k) is k.... you can see it with
#include <stdio.h>
int main()
{
int i=(2,3,7);
printf("%d\n",i);
}
>
Aug 29 '06 #2
dh**********@gmail.com wrote:
if(i,j,k)
printf("welcome");
What i found out after a little experimenting is i,j,k taking
individually as expressions are evaluated .. where as k is used to
evaluate the if condition ....
Look up the comma operator in your friendly C reference. Much shall
thus be made clear to you.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Aug 29 '06 #3
dh**********@gmail.com writes:
if(i,j,k)
This is the "comma operator". The comma operator evaluates its
left-hand operand, then its right-hand operand. Its result is
the value of the right-hand operand. It is most often used in
the expressions in a "for" statement.

If the left-hand operand to a comma operator has no side effect,
as here, then there's no point to doing it at all. When I was
new to the C language, this first surprised me when I was trying
to access a multidimensional array element: a[1,2] is quite
different from a[1][2].
--
"IMO, Perl is an excellent language to break your teeth on"
--Micah Cowan
Aug 29 '06 #4
dh**********@gmail.com wrote:
Hi ..

Well I have a strange code here which i am not usre have a clear
understanding.

I have compiled it on turbo C++3.0 compiler and Devc++ compiler ..
here is the code ..
int main(void)
{
int i=0;,j=10,k=20;
if(i,j,k)
printf("welcome");
else
printf(" Home");
return 0;
}

the output is welcome.
Of course it is: k != 0.
Aug 29 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rob Ristroph | last post by:
Hi, It's pretty unhelpful to post "I have a huge piece of code that crashes in strange places, what's the problem?" but that's basically my problem and I really am at my wit's end. The piece...
7
by: M O J O | last post by:
Hi, I'm developing a asp.net application and ran into a strange css problem. I want all my links to have a dashed underline and when they are hovered, it must change to a solid line. Sounds...
25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
0
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net...
4
by: Nate Murray | last post by:
Hey all, I'm having a strange PHP (4.3.10) problem that seems to have something to do with javascript. This is a bit complex, so hold on to your hats. My issue is that a single function is...
11
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
5
by: Ian | last post by:
Hi everyone, I have found some bizarre (to me...!) behaviour of the Form_Activate function. I have a form which has a button control used to close the form and a subform with a datasheet view...
8
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples....
4
by: kj | last post by:
I'm running into a strange seg fault with the module cjson. The strange part is that it does not occur when I run the code under Emacs' Pydb. Here's an example: import sys, cjson d1 =...
20
by: Pilcrow | last post by:
This behavior seems very strange to me, but I imagine that someone will be able to 'explain' it in terms of the famous C standard. -------------------- code -----------------------------------...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.