Syntax issue

C

Chief

Hey I have a CODE that some 1 wrote however he use this line

x= (y=4,z=6);

( by the way the output of this line is x=6 , y=4 , z=6 )

i was wondring in what situation i will have to use it?
and does it good for?

Second thing Can some 1 explain me the way to use the MAX_RAND while
using rand() I dont understand what does the MAX_RAND do

10x in advance
 
E

Eric Sosman

Chief said:
Hey I have a CODE that some 1 wrote however he use this line

x= (y=4,z=6);

( by the way the output of this line is x=6 , y=4 , z=6 )

i was wondring in what situation i will have to use it?
and does it good for?

Second thing Can some 1 explain me the way to use the MAX_RAND while
using rand() I dont understand what does the MAX_RAND do

10x in advance

dude 4 yr 1st ques its the comma ope8r dont have 2 use it if
u dont want 2 handy some timz anyway c book has all u need 2
no 4 sure 2nd ques no such animal hope this helps ciao babe
 
J

J. J. Farrell

Eric said:
dude 4 yr 1st ques its the comma ope8r dont have 2 use it if
u dont want 2 handy some timz anyway c book has all u need 2
no 4 sure 2nd ques no such animal hope this helps ciao babe

Medic! MEDIC! Even Eric's caught it now. Nobody's safe. Condoms on
fingers everyone.
 
F

Frederick Gotham

Chief posted:
Hey I have a CODE


Culminary Orthogonal Device Ensembles are off-topic here.

x= (y=4,z=6);

( by the way the output of this line is x=6 , y=4 , z=6 )


In C++, maybe. In C, assignment to a variable cannot result in output.

i was wondring in what situation i will have to use it?


<OFF-TOPIC>

When CODE's enter Relax Mode, they tend to over-iterate through arrays --
the only way to normalise the indexing is by using the comma operator in
conjuction with multiple assignments.

and does it good for?


It works quite well (on modern CPU's). Don't try it on a 486.

Second thing Can some 1 explain me the way to use the MAX_RAND while
using rand() I dont understand what does the MAX_RAND do


Yes, indeed:

int max = (MAX_RAND, rand());

(See how I have normalised the over-iteration by using the comma operator
in conjunction with mutiple assignments?)

10x in advance


Whoa whoa whoa, don't get ahead of yourself! If the algorithm which
initialises the CODE is run ten times in advance, the over-iteration will
be far too erratic to correct. Any attempt to normalise the indexing at
that point will result in hard-disk over-burn -- so let's hope you keep
everything backed up.
 
B

Barry Schwarz

Chief posted:



Culminary Orthogonal Device Ensembles are off-topic here.




In C++, maybe. In C, assignment to a variable cannot result in output.

If that were true, then code of the form
if ((ptr = malloc(10)) == NULL)
could never work.

The result of evaluating the assignment operator is the value that is
assigned to the left operand. The statement evaluates as
assign 4 to y
discard result
assign 6 to z
assign result (in this case 6) to x



Remove del for email
 
S

spibou

Eric said:
dude 4 yr 1st ques its the comma ope8r dont have 2 use it if
u dont want 2 handy some timz anyway c book has all u need 2
no 4 sure 2nd ques no such animal hope this helps ciao babe

This gets bookmarked ;-)
 
R

Robert Gamble

Barry said:
If that were true, then code of the form
if ((ptr = malloc(10)) == NULL)
could never work.

The result of evaluating the assignment operator is the value that is
assigned to the left operand. The statement evaluates as
assign 4 to y
discard result
assign 6 to z
assign result (in this case 6) to x

What Mr Gotham said was that variable assignment cannot result in
*output*, in reply to the OP's statement that the assignment resulted
in a line of output.

Robert Gamble
 
F

Frederick Gotham

Barry Schwarz posted:
If that were true, then code of the form
if ((ptr = malloc(10)) == NULL)
could never work.


You're correct. I meant to say I was referring to assignments involving
simple object names:

a = b;

In C++, this could result in output (depending on whether there's a user-
defined assignment operator for the type "a" is).

In C, it can't do anything more than change the value of "a".
 
R

Robert Gamble

Frederick said:
Barry Schwarz posted:



You're correct. I meant to say I was referring to assignments involving
simple object names:

a = b;

In C++, this could result in output (depending on whether there's a user-
defined assignment operator for the type "a" is).

In C, it can't do anything more than change the value of "a".

No legal assignment can result in the printing of output, not just
those involving simple object names.

Robert Gamble
 
F

Frederick Gotham

Robert Gamble posted:
No legal assignment can result in the printing of output, not just
those involving simple object names.


#include <stdio.h>

int main(void)
{
int a,b,c,d,e,f,g;

a = puts("Hello!");
b = puts("Hello!");
c = puts("Hello!");
d = puts("Hello!");
e = puts("Hello!");
f = puts("Hello!");
g = puts("Hello!");

return 0;
}
 
R

Robert Gamble

Frederick said:
Robert Gamble posted:



#include <stdio.h>

int main(void)
{
int a,b,c,d,e,f,g;

a = puts("Hello!");
b = puts("Hello!");
c = puts("Hello!");
d = puts("Hello!");
e = puts("Hello!");
f = puts("Hello!");
g = puts("Hello!");

return 0;
}

Perhaps you don't realize this, but it is the call to the puts function
that results in the output, not the assignment of its return value.

Robert Gamble
 
W

Walter Roberson

Robert Gamble said:
No legal assignment can result in the printing of output, not just
those involving simple object names.

char *IOP = (char *) 0xffff01e4UL;
*IOP = 'h'; *IOP = 'i'; *IOP = '\n';

If address 0xffff01e4 happens to be an IO port, then you could
get the printing of output.

These assignments *are* legal, and converting an integral type
into a pointer is explicitly allowed in the C standard. The result
of all of this is implementation defined, sure, but violates no
constraints.
 
J

jaysome

Hey I have a CODE that some 1 wrote however he use this line

x= (y=4,z=6);

( by the way the output of this line is x=6 , y=4 , z=6 )

i was wondring in what situation i will have to use it?
and does it good for?

I can't think of any good situation in which you will have to use it.
It's not good for anything that I can think of.

If you worked for me and I came across code like this of yours in a
review, I'd tell you that you have two options:

Either change the code to something like this:

int x = 6;
int y = 4;
int z = 6;

or get up out of your chair and walk down the hall to the HR's office,
where you'll be picking up your termination papers. Your (his) code is
indeed Standard C code, but it's not appropriate Standard C code, at
least for the real world.
Second thing Can some 1 explain me the way to use the MAX_RAND while
using rand() I dont understand what does the MAX_RAND do

It's RAND_MAX, not MAX_RAND. There are some C FAQs that deal with this
(search for RAND_MAX at this URL).

http://www.faqs.org/faqs/C-faq/faq/
10x in advance

When I see something like "10x", I think of flyfishing tippet. And
"10x" is very, very fine--and possibly non-existant--flyfishing
tippet. I've never heard of "10x" flyfishing tippet. But that doesn't
mean that you don't fish with "10x" flyfishing tippet--perhaps you do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top