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
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
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
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.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help