freelanceprogrammers.org Forum Index » C
Associative Array
Joined: 25 Jul 2003
Posts: 2
Associative Array
Hi all!
I want to create an class(c++ with wxWindows) to use associative array
like i use in PHP, var["varIndex"]="value", I know I can make things
like this var=myarray("index") using the operator() and this is part of
I want.
The part I don´t know is to do something like this:
myarray("index")=var, using () and = in a once.
If I can´t do in this way, what can I try?
More one question, where can I find docs about std classes?
Thanks!
Joined: 25 Jul 2003
Posts: 5
Associative Array
Hello myself jateen,
i have a small question. Here it
is. Please send me tha correct reason for getting such
answer.
int a=10;
printf("%d,%d,%d",a,a--,a++);
what should be the output?
will it be 10 10 9 or something else check it and send
the answer with reason if its different that what
might u expect.
________________________________________________________________________
Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://uk.messenger.yahoo.com/
Joined: 17 Jul 2003
Posts: 2
Associative Array
10 11 10
The answer is very simple.
It will do the calculations from Right to left,
instead of left to right.
So first a++ wich will get 10 for rightmost value and
increments a to 11.
Then it will do a-- to get 11 for middle value and
decrements a to 10.
Now a value is 10 and left most value is printed.
correct me if I was wrong.
Kiran
--- jateen bodkhe <jateen_b@...> wrote:
---------------------------------
Hello myself jateen,
i have a small question. Here it
is. Please send me tha correct reason for getting such
answer.
int a=10;
printf("%d,%d,%d",a,a--,a++);
what should be the output?
will it be 10 10 9 or something else check it and send
the answer with reason if its different that what
might u expect.
________________________________________________________________________
Want to chat instantly with your online friends? Get
the FREE Yahoo!
Messenger http://uk.messenger.yahoo.com/
Yahoo! Groups SponsorADVERTISEMENT
var lrec_target="_top";var lrec_URL = new
Array();lrec_URL[1] =
"http://rd.yahoo.com/M=256694.3632754.4898347.1261774/D=egroupweb/S=1705006788:H
M/A=1683996/R=0/id=flashurl/SIG=11if1rb57/*http://webevents.yahoo.com/universal/
seabiscuit/";var
link="javascript:LRECopenWindow(1)";var lrec_flashfile
=
`http://webevents.yahoo.com/universal/seabiscuit/lrec/AdVision_lrec.swf?clickTAG
=`+link+``;var
lrec_altURL =
"http://rd.yahoo.com/M=256694.3632754.4898347.1261774/D=egroupweb/S=1705006788:H
M/A=1683996/R=1/id=altimgurl/SIG=11if1rb57/*http://webevents.yahoo.com/universal
/seabiscuit/";var
lrec_altimg =
"http://webevents.yahoo.com/universal/seabiscuit/lrec/noflash.gif";var
lrec_width = 300;var lrec_height = 250;
Keep posting
Your use of Yahoo! Groups is subject to the Yahoo!
Terms of Service.
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Joined: 25 Jul 2003
Posts: 3
Associative Array
Hay Good question,
watt my understanding says is ...
The answer is 10 10 10 .
Y, B`coz of stack. As we know the value go into
stack by pascal convension,
i.e from Left to Right.
when the value goes on to printf stack, first only
and only `a = 10` values goies on to stack.
means the first elemnt will be 10,second will be 10
and the third will be 10, as we know in C if we give
++ or -- after the variable, first the variable will
be assigned then incremented or decremented.
During actual printing first 10(first pop done) will
be printed, then 10 will be printed as 10 is ther next
in the stack (Pop done), then the a value is assigned
to 9 (a = a - 1 (a--)), then 10 will bw printed as 10
is ther in the stack (3rd Pop out), then a = a + 1 is
done (9 + 1) 10.
so after all this if u give a printf to a O/P would be
10.
Plz think w.r.t constants (10) n not w.r.t variable
(a)..
if i m wrong plz clear it ..
regards
Patnaik
--- jateen bodkhe <jateen_b@...> wrote:
> Hello myself jateen,
> i have a small question. Here
> it
> is. Please send me tha correct reason for getting
> such
> answer.
> int a=10;
> printf("%d,%d,%d",a,a--,a++);
>
> what should be the output?
> will it be 10 10 9 or something else check it and
> send
> the answer with reason if its different that what
> might u expect.
>
>
>
________________________________________________________________________
> Want to chat instantly with your online friends?
> Get the FREE Yahoo!
> Messenger http://uk.messenger.yahoo.com/
>
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Joined: 28 Jul 2003
Posts: 3
Associative Array
Hi
The answer depends on the order of evaluation of the arguments, which is not
defined by the C language. Therefore any answer is "correct", and might be
different every time you run the program (although it probably won`t be).
John
-----Original Message-----
From: N.D.Patnaik [mailto:ndpatnaik@...]
Hay Good question,
watt my understanding says is ...
The answer is 10 10 10 .
Y, B`coz of stack. As we know the value go into
stack by pascal convension,
i.e from Left to Right.
when the value goes on to printf stack, first only
and only `a = 10` values goies on to stack.
means the first elemnt will be 10,second will be 10
and the third will be 10, as we know in C if we give
++ or -- after the variable, first the variable will
be assigned then incremented or decremented.
During actual printing first 10(first pop done) will
be printed, then 10 will be printed as 10 is ther next
in the stack (Pop done), then the a value is assigned
to 9 (a = a - 1 (a--)), then 10 will bw printed as 10
is ther in the stack (3rd Pop out), then a = a + 1 is
done (9 + 1) 10.
so after all this if u give a printf to a O/P would be
10.
Plz think w.r.t constants (10) n not w.r.t variable
(a)..
if i m wrong plz clear it ..
regards
Patnaik
--- jateen bodkhe <jateen_b@...> wrote:
> Hello myself jateen,
> i have a small question. Here
> it
> is. Please send me tha correct reason for getting
> such
> answer.
> int a=10;
> printf("%d,%d,%d",a,a--,a++);
>
> what should be the output?
> will it be 10 10 9 or something else check it and
> send
> the answer with reason if its different that what
> might u expect.
Joined: 25 Jul 2003
Posts: 1
Associative Array
Hello everybody,
Well, the statement is quite confusing.
The output is completely dependent on the compiler you use.
If u use gcc then output is : 10 10 9
If u use MS VC++ output is : 10 10 10
May be if u use Turbo C u will get 10 11 10. ( I havent tried on Turbo C ).
In gcc the parameters are evaluated from left and right and in place. Thats why after (a--) when u print the value of (a++) it prints 9.
After this if u print the value of `a ` then it will be 10.
But in VC++ the parameters are evaluated from right to left and the post increment/decrement operations are postponed to next statement.
Thats why u get 10 10 10.
After this if u print the value of `a ` then also it will be 10, as one ++ and one -- neutralize each other.
I guess in Turbo C, the order of evaluation is from right to left and in place. Thats why u may be getting 10 11 10.
After this if u print the value of `a ` then it will be 10 only.
About Turbo C this is just my guess, I havent tried it.
Hope I am correct.
Cheers,
- Raghavendra.
-----Original Message-----From: N.D.Patnaik [mailto:ndpatnaik@...] Sent: Friday, July 25, 2003 5:54 PMTo: Programmers-Town@yahoogroups.comSubject: Re: Re: *(&Programmers-Town&)* a small questionHay Good question,watt my understanding says is ... The answer is 10 10 10 . Y, B`coz of stack. As we know the value go intostack by pascal convension, i.e from Left to Right.when the value goes on to printf stack, first onlyand only `a = 10` values goies on to stack. means the first elemnt will be 10,second will be 10and the third will be 10, as we know in C if we give++ or -- after the variable, first the variable willbe assigned then incremented or decremented. During actual printing first 10(first pop done) willbe printed, then 10 will be printed as 10 is ther nextin the stack (Pop done), then the a value is assignedto 9 (a = a - 1 (a--)), then 10 will bw printed as 10is ther in the stack (3rd Pop out), then a = a + 1 isdone (9 + 1) 10.so after all this if u give a printf to a O/P would be10. Plz think w.r.t constants (10) n not w.r.t variable(a)..if i m wrong plz clear it ..regardsPatnaik--- jateen bodkhe <jateen_b@...> wrote:> Hello myself jateen,> i have a small question. Here> it> is. Please send me tha correct reason for getting> such> answer.> int a=10;> printf("%d,%d,%d",a,a--,a++);> > what should be the output?> will it be 10 10 9 or something else check it and> send> the answer with reason if its different that what> might u expect.> > >________________________________________________________________________> Want to chat instantly with your online friends? > Get the FREE Yahoo!> Messenger http://uk.messenger.yahoo.com/> > __________________________________Do you Yahoo!?Yahoo! SiteBuilder - Free, easy-to-use web site design softwarehttp://sitebuilder.yahoo.comKeep posting Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Joined: 25 Jul 2003
Posts: 48
Associative Array
See reply embedded...
> -----Original Message-----
> From: jateen bodkhe [mailto:jateen_b@...]
> Sent: Friday, July 25, 2003 04:45
> To: Programmers-Town@yahoogroups.com
> Subject: *(&Programmers-Town&)* a small question
>
> Hello myself jateen,
> i have a small question. Here it
> is. Please send me tha correct reason for getting such
> answer.
> int a=10;
> printf("%d,%d,%d",a,a--,a++);
^^^^^^^^
Undefined behavior.
< http://www.eskimo.com/~scs/C-faq/q3.2.html >
< http://www.eskimo.com/~scs/C-faq/q3.8.html >
> what should be the output?
As for undefined behavior, the output can be anything, including no
output, program crashes, system crashes, reformatting your hard drive,
etc...
> will it be 10 10 9 or something else check it and send
> the answer with reason if its different that what
> might u expect.
The reason is because `a` is being modified more at once between
sequence points.
HTH
Shyan
Joined: 25 Jul 2003
Posts: 48
Associative Array
Hi,
Reply/comments embedded....
> -----Original Message-----
> From: chava kirankumar [mailto:chavakk19@...]
> Sent: Friday, July 25, 2003 07:15
> To: Programmers-Town@yahoogroups.com
> Subject: Re: *(&Programmers-Town&)* a small question
>
> 10 11 10
> The answer is very simple.
> It will do the calculations from Right to left,
No. Evaluation of function argument is not guaranteed to be of any
order. The compiler can evaluate the arguments in any order it seems
fit based on the optimization settings at compiled time.
Do not confuse order of evaluation verses order of argument passing.
Order of argument passing depends on calling conventions.
HTH
Shyan
Joined: 19 Jul 2003
Posts: 29
Associative Array
Sadly, this is compiler-implementation specific.
Neither C nor C++ specifies the order in which the
sub-expressions of an expression are evaluated.
On GCC 3.2, it gave me 10, 11, 10. So, there!
Regards,
Shantanu
--- "N.D.Patnaik" <ndpatnaik@...> wrote:
> Hay Good question,
> watt my understanding says is ...
>
> The answer is 10 10 10 .
> Y, B`coz of stack. As we know the value go into
> stack by pascal convension,
> i.e from Left to Right.
>
> when the value goes on to printf stack, first only
> and only `a = 10` values goies on to stack.
> means the first elemnt will be 10,second will be
> 10
> and the third will be 10, as we know in C if we give
> ++ or -- after the variable, first the variable will
> be assigned then incremented or decremented.
>
> During actual printing first 10(first pop done)
> will
> be printed, then 10 will be printed as 10 is ther
> next
> in the stack (Pop done), then the a value is
> assigned
> to 9 (a = a - 1 (a--)), then 10 will bw printed as
> 10
> is ther in the stack (3rd Pop out), then a = a + 1
> is
> done (9 + 1) 10.
>
> so after all this if u give a printf to a O/P would
> be
> 10.
> Plz think w.r.t constants (10) n not w.r.t
> variable
> (a)..
>
> if i m wrong plz clear it ..
>
> regards
> Patnaik
> --- jateen bodkhe <jateen_b@...> wrote:
> > Hello myself jateen,
> > i have a small question.
> Here
> > it
> > is. Please send me tha correct reason for getting
> > such
> > answer.
> > int a=10;
> > printf("%d,%d,%d",a,a--,a++);
> >
> > what should be the output?
> > will it be 10 10 9 or something else check it and
> > send
> > the answer with reason if its different that what
> > might u expect.
> >
> >
> >
>
________________________________________________________________________
> > Want to chat instantly with your online friends?
> > Get the FREE Yahoo!
> > Messenger http://uk.messenger.yahoo.com/
> >
> >
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site
> design software
> http://sitebuilder.yahoo.com
>
>
> ------------------------ Yahoo! Groups Sponsor
> ---------------------~-->
> Buy Ink Cartridges & Refill Kits for Your Epson at
> Myinks.com
> Free shipping on orders $50 or more to the US and
> Canada.
>
http://www.c1tracking.com/l.asp?cid=5705&lp=home/epson.asp
>
http://us.click.yahoo.com/brYXfA/_xWGAA/ySSFAA/EbFolB/TM
>
---------------------------------------------------------------------~->
>
> Keep posting
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Joined: 19 Jul 2003
Posts: 29
Associative Array
--- chava kirankumar <chavakk19@...> wrote:
> 10 11 10
> The answer is very simple.
> It will do the calculations from Right to left,
> instead of left to right.
> So first a++ wich will get 10 for rightmost value
> and
> increments a to 11.
> Then it will do a-- to get 11 for middle value and
> decrements a to 10.
> Now a value is 10 and left most value is printed.
> correct me if I was wrong.
Well, the answer might be simple, but I guess the
explanation is not. Will you mind explaining why the
calculatioons should be done from right to left, and
not vice versa? I mean, which operator/precedence rule
says that?
Regards,
Shantanu
>
> Kiran
>
> --- jateen bodkhe <jateen_b@...> wrote:
>
> ---------------------------------
> Hello myself jateen,
> i have a small question. Here
> it
> is. Please send me tha correct reason for getting
> such
> answer.
> int a=10;
> printf("%d,%d,%d",a,a--,a++);
>
> what should be the output?
> will it be 10 10 9 or something else check it and
> send
> the answer with reason if its different that what
> might u expect.
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Joined: 19 Jul 2003
Posts: 29
Associative Array
--- Fernando_Concei�o <fernando.listas@...>
wrote:
> Hi all!
> I want to create an class(c++ with wxWindows) to use
> associative array
> like i use in PHP, var["varIndex"]="value", I know I
> can make things
> like this var=myarray("index") using the operator()
> and this is part of
> I want.
> The part I dont know is to do something like this:
> myarray("index")=var, using () and = in a once.
> If I cant do in this way, what can I try?
>
> More one question, where can I find docs about std
> classes?
That`s interesting. But doesn`t the LHS have to be an
L-value to make this possible, which it isn`t? So,
that brings us back to maps. Maps are already elegant
anyway, no? :-)
Regards,
Shantanu
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Joined: 26 Jul 2003
Posts: 4
Associative Array
hi
this is implementataion dependent ,
most of the compilers support right to left evaluation
and but compiler on HP- UX system evaluated from right
to left.
bye
Rajaram
--- Shantanu Kumar <shantanu_k06@...> wrote:
> --- chava kirankumar <chavakk19@...> wrote:
> > 10 11 10
> > The answer is very simple.
> > It will do the calculations from Right to left,
> > instead of left to right.
> > So first a++ wich will get 10 for rightmost value
> > and
> > increments a to 11.
> > Then it will do a-- to get 11 for middle value and
> > decrements a to 10.
> > Now a value is 10 and left most value is printed.
> > correct me if I was wrong.
>
> Well, the answer might be simple, but I guess the
> explanation is not. Will you mind explaining why the
> calculatioons should be done from right to left, and
> not vice versa? I mean, which operator/precedence
> rule
> says that?
>
> Regards,
> Shantanu
>
> >
> > Kiran
> >
> > --- jateen bodkhe <jateen_b@...> wrote:
> >
> > ---------------------------------
> > Hello myself jateen,
> > i have a small question.
> Here
> > it
> > is. Please send me tha correct reason for getting
> > such
> > answer.
> > int a=10;
> > printf("%d,%d,%d",a,a--,a++);
> >
> > what should be the output?
> > will it be 10 10 9 or something else check it and
> > send
> > the answer with reason if its different that what
> > might u expect.
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site
> design software
> http://sitebuilder.yahoo.com
>
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Joined: 26 Jul 2003
Posts: 4
Associative Array
as far as my understanding for "sequence points" goes
in a++ a is changed only once between sequnce points
as , is a sequnce point so this is not undefined.
correct me if i`m wrong
Rajaram
--- Shyan Lam <lam@...> wrote:
> See reply embedded...
>
> > -----Original Message-----
> > From: jateen bodkhe [mailto:jateen_b@...]
> > Sent: Friday, July 25, 2003 04:45
> > To: Programmers-Town@yahoogroups.com
> > Subject: *(&Programmers-Town&)* a small question
> >
> > Hello myself jateen,
> > i have a small question.
> Here it
> > is. Please send me tha correct reason for getting
> such
> > answer.
> > int a=10;
> > printf("%d,%d,%d",a,a--,a++);
> ^^^^^^^^
> Undefined behavior.
> < http://www.eskimo.com/~scs/C-faq/q3.2.html >
> < http://www.eskimo.com/~scs/C-faq/q3.8.html >
>
> > what should be the output?
>
> As for undefined behavior, the output can be
> anything, including no
> output, program crashes, system crashes,
> reformatting your hard drive,
> etc...
>
> > will it be 10 10 9 or something else check it and
> send
> > the answer with reason if its different that what
> > might u expect.
>
> The reason is because `a` is being modified more at
> once between
> sequence points.
>
> HTH
> Shyan
>
>
>
>
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Joined: 14 Jul 2003
Posts: 2
Associative Array
that was a good one this answers everyones question on precedence i supposeShyan Lam <lam@...> wrote:
See reply embedded...> -----Original Message-----> From: jateen bodkhe [mailto:jateen_b@...]> Sent: Friday, July 25, 2003 04:45> To: Programmers-Town@yahoogroups.com> Subject: *(&Programmers-Town&)* a small question> > Hello myself jateen,> i have a small question. Here it> is. Please send me tha correct reason for getting such> answer.> int a=10;>
printf("%d,%d,%d",a,a--,a++); ^^^^^^^^Undefined behavior. < http://www.eskimo.com/~scs/C-faq/q3.2.html > < http://www.eskimo.com/~scs/C-faq/q3.8.html >> what should be the output?As for undefined behavior, the output can be anything, including nooutput, program crashes, system crashes, reformatting your hard drive,etc...> will it be 10 10 9 or something else check it and send> the answer with reason if its different that what> might u expect.The reason is because `a` is being modified more at once betweensequence
points.HTHShyanKeep posting Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
SMS using the Yahoo! Messenger;
Download latest version.
Joined: 25 Jul 2003
Posts: 2
Associative Array
Sorry, but what is "LHS", "L-value" and "Maps"?
Thanks!
Shantanu Kumar escreveu:
>--- Fernando_Concei�o <fernando.listas@...>
>wrote:
>
>
>>Hi all!
>>I want to create an class(c++ with wxWindows) to use
>>associative array
>>like i use in PHP, var["varIndex"]="value", I know I
>>can make things
>>like this var=myarray("index") using the operator()
>>and this is part of
>>I want.
>>The part I dont know is to do something like this:
>>myarray("index")=var, using () and = in a once.
>>If I cant do in this way, what can I try?
>>
>>More one question, where can I find docs about std
>>classes?
>>
>>
>
>That`s interesting. But doesn`t the LHS have to be an
>L-value to make this possible, which it isn`t? So,
>that brings us back to maps. Maps are already elegant
>anyway, no? :-)
>
>Regards,
>Shantanu
>
>__________________________________
>Do you Yahoo!?
>Yahoo! SiteBuilder - Free, easy-to-use web site design software
>http://sitebuilder.yahoo.com
>
>
>
>Keep posting
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
>
>
>
All times are GMT
Page 1 of 2
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







