freelanceprogrammers.org Forum Index » C

(Query): Need Answers


View user's profile Post To page top
vickymsis@... Posted: Wed Dec 22, 2004 9:49 pm


Joined: 22 Dec 2004

Posts: 2
(Query): Need Answers
1)Whats the diff between
// What it will do ?
-- for(;;);

// Next
-- func()
-- {
-- func();
-- }

what kind of output we can get ?

2)
main()
{
int x =5, y;
y = size(++x);
printf("X = %d", x);
}
Prints X = 5 only Why ?

bye
Vikram



__________________________________
Do you Yahoo!?
Jazz up your holiday email with celebrity designs. Learn more.
http://celebrity.mail.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
shabble Posted: Wed Dec 29, 2004 5:44 pm


Joined: 29 Dec 2004

Posts: 31
(Query): Need Answers
From: Vikram [mailto:vickymsis@...]

>1)Whats the diff between
>// What it will do ?
>-- for(;;);

Not a lot for a very long time, (probably) using lots of CPU

>// Next
>-- func()
>-- {
>-- func();
>-- }
>
>what kind of output we can get ?

Not a lot for a very short time, using lots of memory. Then somthing
similar to a core dump.

>2)
> main()
>{
> int x =5, y;
> y = size(++x);
> printf("X = %d", x);
>}
>Prints X = 5 only Why ?

Answered elsewhere.

--
PJH

"Real programmers can write assembly code in any language." - Larry Wall






Alderley plc, Arnolds Field Estate, The Downs, Wickwar, Gloucestershire, GL12
8JD, UK
Tel: +44(0)1454 294556 Fax: +44 (0)1454 299272

Website : www.alderley.com Sales : sales@... Service :
service@...

This email and its contents are confidential and are solely for the use of the
intended recipient. If you are not the original recipient you have received it
in error and any use, dissemination, forwarding, printing or copying of this
email is strictly prohibited. Should you receive this email in error please
immediately notify it@...

This email has been scanned for viruses, however you should always scan emails
with your own systems prior to opening.
Reply with quote
Send private message
View user's profile Post To page top
guru_bo Posted: Wed Dec 29, 2004 10:35 pm


Joined: 29 Dec 2004

Posts: 2
(Query): Need Answers
> 1)Whats the diff between
> // What it will do ?
> -- for(;;);
>
> // Next
> -- func()
> -- {
> -- func();
> -- }

Ans:
Both will go in Infinite Loop


> what kind of output we can get ?
>
> 2)
> main()
> {
> int x =5, y;
> y = size(++x);
> printf("X = %d", x);
> }
> Prints X = 5 only Why ?
>

Ans:

I am not sure,, but what i think is may be sizeof
operator will take datatype of the variable during
calculation not the value, so may be before
calculating it may come to know about data type.

My reasoning may be incorrect, if wrong let me correct
myself
Bye


> bye
> Vikram
>
>
>
> __________________________________
> Do you Yahoo!?
> Jazz up your holiday email with celebrity designs.
> Learn more.
> http://celebrity.mail.yahoo.com
>
>
>
>




__________________________________
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
Reply with quote
Send private message
View user's profile Post To page top
shabble Posted: Wed Dec 29, 2004 10:43 pm


Joined: 29 Dec 2004

Posts: 31
(Query): Need Answers
From: gururaj bo [mailto:guru_bo@...]
>> 1)Whats the diff between
>> // What it will do ?
>> -- for(;;);
>>
>> // Next
>> -- func()
>> -- {
>> -- func();
>> -- }
>
>Ans:
>Both will go in Infinite Loop

One will. The other will run out of memory long before then.

--
PJH

bug, n: An elusive creature living in a program that makes it incorrect.
The activity of "debugging", or removing bugs from a program, ends when
people get tired of doing it, not when the bugs are removed. -
"Datamation", January 15, 1984




Alderley plc, Arnolds Field Estate, The Downs, Wickwar, Gloucestershire, GL12
8JD, UK
Tel: +44(0)1454 294556 Fax: +44 (0)1454 299272

Website : www.alderley.com Sales : sales@... Service :
service@...

This email and its contents are confidential and are solely for the use of the
intended recipient. If you are not the original recipient you have received it
in error and any use, dissemination, forwarding, printing or copying of this
email is strictly prohibited. Should you receive this email in error please
immediately notify it@...

This email has been scanned for viruses, however you should always scan emails
with your own systems prior to opening.
Reply with quote
Send private message
View user's profile Post To page top
skumaran_1980 Posted: Fri Dec 31, 2004 1:41 pm


Joined: 31 Dec 2004

Posts: 2
(Query): Need Answers
Paul Herring <pherring@...> wrote:

From: Vikram [mailto:vickymsis@...] >1)Whats the diff between>// What it will do ?>-- for(;;);Not a lot for a very long time, (probably) using lots of CPU>// Next>-- func()>-- {>--    func();>-- }>>what kind of output we can get ?Not a lot for a very short time, using lots of memory. Then somthingsimilar to a core dump.>2)> main()>{>  int x =5, y;>  y = size(++x);>  printf("X = %d", x);>}>Prints X = 5 only Why ?Answered elsewhere.
I am getting an answer of 6 which is what is correct. I am using Microsoft Visual 6 Enterprise Edition.
Regards,
S. Kumaran.
To unsubscribe : programmers-town-unsubscribe@yahoogroups.com__________________________________________________Do You Yahoo!?Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
ashwin_mittal26 Posted: Fri Dec 31, 2004 6:23 pm


Joined: 27 Dec 2004

Posts: 14
(Query): Need Answers
--- kumaran subramanian <skumaran_1980@...>
wrote:

>
>
> Paul Herring <pherring@...> wrote:
>
> From: Vikram [mailto:vickymsis@...]
>
> >1)Whats the diff between
> >// What it will do ?
> >-- for(;;);
>
> Not a lot for a very long time, (probably) using
> lots of CPU
>
> >// Next
> >-- func()
> >-- {
> >-- func();
> >-- }
> >
> >what kind of output we can get ?
>
> Not a lot for a very short time, using lots of
> memory. Then somthing
> similar to a core dump.
>
> >2)
> > main()
> >{
> > int x =5, y;
> > y = size(++x);
> > printf("X = %d", x);
> >}
> >Prints X = 5 only Why ?
>
> Answered elsewhere.
>
> I am getting an answer of 6 which is what is
> correct. I am using Microsoft Visual 6 Enterprise
> Edition.
>
>
> Regards,
>
> S. Kumaran.


It depends from coompiler to compiler.

Regards,
Ashwin Mittal.



__________________________________
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250
Reply with quote
Send private message
View user's profile Post To page top
sg7650 Posted: Sun Jan 02, 2005 4:47 pm


Joined: 02 Jan 2005

Posts: 5
(Query): Need Answers
Hi,

pls correct me in case i am wrong
--- In Programmers-Town@yahoogroups.com, gururaj bo <guru_bo@y...> wrote:
> > 2)
> > main()
> > {
> > int x =5, y;
> > y = size(++x);
> > printf("X = %d", x);
> > }
> > Prints X = 5 only Why ?
> >
> I am not sure,, but what i think is may be sizeof
> operator will take datatype of the variable during
> calculation not the value, so may be before
> calculating it may come to know about data type.
>
I think this is because when we pass an argument (by value) to a
function a copy of the argument is made and is passed to the function.
Since we are incrementing X while passing, it is the copy which gets
affected and not the original one. So in the next statement we are
getting the answer as 5.

Bye
Sumit Garg
Reply with quote
Send private message
View user's profile Post To page top
kishor_grep Posted: Tue Jan 04, 2005 9:32 am


Joined: 04 Jan 2005

Posts: 2
(Query): Need Answers
--- Sumit Garg <sg7650@...> wrote:

>
>
> Hi,
>
> pls correct me in case i am wrong
> --- In Programmers-Town@yahoogroups.com, gururaj bo
> <guru_bo@y...> wrote:
> > > 2)
> > > main()
> > > {
> > > int x =5, y;
> > > y = size(++x);
> > > printf("X = %d", x);
> > > }
> > > Prints X = 5 only Why ?
> > >
> > I am not sure,, but what i think is may be sizeof
> > operator will take datatype of the variable during
> > calculation not the value, so may be before
> > calculating it may come to know about data type.
> >
> I think this is because when we pass an argument (by
> value) to a
> function a copy of the argument is made and is
> passed to the function.
> Since we are incrementing X while passing, it is the
> copy which gets
> affected and not the original one. So in the next
> statement we are
> getting the answer as 5.
>
> Bye
> Sumit Garg


Hi,

My opinion the reason is related to concepts like Pre
increment and Post increment. Pls comment.

Regards
Kishor



__________________________________
Do you Yahoo!?
All your favorites on one personal page – Try My Yahoo!
http://my.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
avbarve2k2 Posted: Tue Jan 04, 2005 12:50 pm


Joined: 04 Jan 2005

Posts: 1
(Query): Need Answers
Hi,

> My opinion the reason is related to concepts like Pre
> increment and Post increment. Pls comment.

sizeof( ) doesnt evaluate nething. It just prints out the extact
size (May not be exact in case of padding) of the object/variable
passed.

Cheers
Abhijeet




----- Original Message -----
From: "Kishor Karuvath" <kishor_grep@...>
To: <Programmers-Town@yahoogroups.com>
Sent: Tuesday, January 04, 2005 9:02 AM
Subject: Re: (PT)(Query): Need Answers


>
>
> --- Sumit Garg <sg7650@...> wrote:
>
> >
> >
> > Hi,
> >
> > pls correct me in case i am wrong
> > --- In Programmers-Town@yahoogroups.com, gururaj bo
> > <guru_bo@y...> wrote:
> > > > 2)
> > > > main()
> > > > {
> > > > int x =5, y;
> > > > y = size(++x);
> > > > printf("X = %d", x);
> > > > }
> > > > Prints X = 5 only Why ?
> > > >
> > > I am not sure,, but what i think is may be sizeof
> > > operator will take datatype of the variable during
> > > calculation not the value, so may be before
> > > calculating it may come to know about data type.
> > >
> > I think this is because when we pass an argument (by
> > value) to a
> > function a copy of the argument is made and is
> > passed to the function.
> > Since we are incrementing X while passing, it is the
> > copy which gets
> > affected and not the original one. So in the next
> > statement we are
> > getting the answer as 5.
> >
> > Bye
> > Sumit Garg
>
>
> Hi,
>
> My opinion the reason is related to concepts like Pre
> increment and Post increment. Pls comment.
>
> Regards
> Kishor
>
>
>
> __________________________________
> Do you Yahoo!?
> All your favorites on one personal page - Try My Yahoo!
> http://my.yahoo.com
>
>
>
>
>
> To unsubscribe : programmers-town-unsubscribe@yahoogroups.com
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
Reply with quote
Send private message
View user's profile Post To page top
smahesh555 Posted: Fri Jan 07, 2005 9:17 pm


Joined: 07 Jan 2005

Posts: 3
(Query): Need Answers
As far as I know sizeof() does it work at compile time. So at compile
time, it just looks at the type of the object given to it, and puts
that value there. So in furthur steps of compilation the code
available is "y = 2" and not y = sizeof(++x);


On Tue, 4 Jan 2005 12:20:08 +0530, Abhijeet Barve
<abhijeet_barve@...> wrote:
>
> Hi,
>
> > My opinion the reason is related to concepts like Pre
> > increment and Post increment. Pls comment.
>
> sizeof( ) doesnt evaluate nething. It just prints out the extact
> size (May not be exact in case of padding) of the object/variable
> passed.
>
> Cheers
> Abhijeet
>
>
>
>
>
> ----- Original Message -----
> From: "Kishor Karuvath" <kishor_grep@...>
> To: <Programmers-Town@yahoogroups.com>
> Sent: Tuesday, January 04, 2005 9:02 AM
> Subject: Re: (PT)(Query): Need Answers
>
>
> >
> >
> > --- Sumit Garg <sg7650@...> wrote:
> >
> > >
> > >
> > > Hi,
> > >
> > > pls correct me in case i am wrong
> > > --- In Programmers-Town@yahoogroups.com, gururaj bo
> > > <guru_bo@y...> wrote:
> > > > > 2)
> > > > > main()
> > > > > {
> > > > > int x =5, y;
> > > > > y = size(++x);
> > > > > printf("X = %d", x);
> > > > > }
> > > > > Prints X = 5 only Why ?
> > > > >
> > > > I am not sure,, but what i think is may be sizeof
> > > > operator will take datatype of the variable during
> > > > calculation not the value, so may be before
> > > > calculating it may come to know about data type.
> > > >
> > > I think this is because when we pass an argument (by
> > > value) to a
> > > function a copy of the argument is made and is
> > > passed to the function.
> > > Since we are incrementing X while passing, it is the
> > > copy which gets
> > > affected and not the original one. So in the next
> > > statement we are
> > > getting the answer as 5.
> > >
> > > Bye
> > > Sumit Garg
> >
> >
> > Hi,
> >
> > My opinion the reason is related to concepts like Pre
> > increment and Post increment. Pls comment.
> >
> > Regards
> > Kishor
> >
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > All your favorites on one personal page - Try My Yahoo!
> > http://my.yahoo.com
> >
> >
> >
> >
> >
> > To unsubscribe : programmers-town-unsubscribe@yahoogroups.com
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
>
>
>
>
>
>
> To unsubscribe : programmers-town-unsubscribe@yahoogroups.com
>
>
>
>
> ________________________________
> Yahoo! Groups Links
> To visit your group on the web, go to:
> http://groups.yahoo.com/group/Programmers-Town/
>
> To unsubscribe from this group, send an email to:
> Programmers-Town-unsubscribe@yahoogroups.com
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
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
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