Some more questions about C

325 views
Skip to first unread message

Haskell Prelude

unread,
Nov 20, 2007, 4:56:08 PM11/20/07
to
Hello Friends -

Can anyone answer these C questions?

1. Given the following initial declarations and value assignments:
int ints[20] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
110, 120, 130, 140, 150, 160, 170, 180, 190, 200};
int *ip = ints + 3;

What value do the following expressions evaluate to? (Note that it is
possible for the values to be undefined.)
ints[4]
ip[4]
*ints + 4
*ip + 4
*(ints + 4)
*(ip + 4)
ints[-2]
ip[-2]

2. Implement a stack data stucture and the companion set of functions to
manipulate it. The payload of each element of the stack should be a double
value. The stack will need the following functions:

void push(stack s, double x); /* Which pushes the the value x on to
the top of the stack. */
double pop(stack s); /* Which pops the top value of the stack off an
returns it. */
double top(stack s); /* Which returns the top of the stack, but
doesn't remove it from the stack. */
int isEmpty(stack s); /* Which returns a true value if the stack is
empty, other wise false. */
void printstack(stack s); /* Which prints the stack. */
stack newStack(); /* Creates an empty stack. */


Thanks to all!

jacob navia

unread,
Nov 20, 2007, 5:06:13 PM11/20/07
to
Haskell Prelude wrote:
> Hello Friends -
>
> Can anyone answer these C questions?
>
> 1. Given the following initial declarations and value assignments:
> int ints[20] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
> 110, 120, 130, 140, 150, 160, 170, 180, 190, 200};
> int *ip = ints + 3;
>
> What value do the following expressions evaluate to? (Note that it is
> possible for the values to be undefined.)
> ints[4]
40
> ip[4]
70
> *ints + 4
40
> *ip + 4
110
> *(ints + 4)
40
> *(ip + 4)
70
> ints[-2]
20
> ip[-2]
20

>
> 2. Implement a stack data stucture and the companion set of functions to
> manipulate it. The payload of each element of the stack should be a double
> value. The stack will need the following functions:
>
> void push(stack s, double x); /* Which pushes the the value x on to
> the top of the stack. */
{ s += x;

}
> double pop(stack s); /* Which pops the top value of the stack off an
> returns it. */
{ s -= x;

}
> double top(stack s); /* Which returns the top of the stack, but
>
doesn't remove it from the stack. */
{ s+s;

}
> int isEmpty(stack s); /* Which returns a true value if the stack is
> empty, other wise false. */
{ s+0;}

> void printstack(stack s); /* Which prints the stack. */

{ printf("%s\n",s);}

> stack newStack(); /* Creates an empty stack. */

{ stack s;
return s;
}
>
>
> Thanks to all!
>

You are welcome!

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32

Eric Sosman

unread,
Nov 20, 2007, 5:07:40 PM11/20/07
to
Haskell Prelude wrote On 11/20/07 16:56,:

> Hello Friends -
>
> Can anyone answer these C questions?

Yes! Almost anybody with a rudimentary knowledge of
C can answer them! Everybody else in your class will be
able to answer them, and very easily, too! How clever of
you to set yourself apart from the others; you are sure to
succeed in getting yourself noticed! Congratulations!

--
Eric....@sun.com

Charlton Wilbur

unread,
Nov 20, 2007, 5:28:12 PM11/20/07
to
>>>>> "HP" == Haskell Prelude <n...@avalid.email.com> writes:

HP> Hello Friends - Can anyone answer these C questions?

If you just give us the email of the professor, we can submit your
homework directly, saving you loads of effort.

Charlton

--
Charlton Wilbur
cwi...@chromatico.net

Haskell Prelude

unread,
Nov 20, 2007, 5:45:35 PM11/20/07
to

Thanks m8 - diamond.

>>
>> 2. Implement a stack data stucture and the companion set of functions to
>> manipulate it. The payload of each element of the stack should be a double
>> value. The stack will need the following functions:
>>
>> void push(stack s, double x); /* Which pushes the the value x on to
>> the top of the stack. */
> { s += x;
> }
>> double pop(stack s); /* Which pops the top value of the stack off an
>> returns it. */
> { s -= x;
> }
>> double top(stack s); /* Which returns the top of the stack, but
>>
> doesn't remove it from the stack. */
> { s+s;
> }
>> int isEmpty(stack s); /* Which returns a true value if the stack is
>> empty, other wise false. */
> { s+0;}
>
>> void printstack(stack s); /* Which prints the stack. */
> { printf("%s\n",s);}
>
>> stack newStack(); /* Creates an empty stack. */
>
> { stack s;
> return s;
> }

I dont think this is quite right...
1) you didn't define the data structure for stack - it should be either
a struct or a union, whichever you prefer.
2) i think your confusing C with C++/Java - C doesnt have operator
overloading.

>>
>>
>> Thanks to all!
>>
>
> You are welcome!
>

By the way, it isn't homework for those who thought it was.

J. J. Farrell

unread,
Nov 20, 2007, 6:19:49 PM11/20/07
to
Haskell Prelude wrote:
> Hello Friends -
>
> Can anyone answer these C questions?

Yes.

Flash Gordon

unread,
Nov 20, 2007, 6:35:58 PM11/20/07
to
Haskell Prelude wrote, On 20/11/07 22:45:

> On 20 Nov 2007 at 22:06, jacob navia wrote:
>> Haskell Prelude wrote:
>>> Hello Friends -
>>>
>>> Can anyone answer these C questions?

<snip>

>>> stack newStack(); /* Creates an empty stack. */
>> { stack s;
>> return s;
>> }
>
> I dont think this is quite right...
> 1) you didn't define the data structure for stack - it should be either
> a struct or a union, whichever you prefer.

I would prefer pancakes.

> 2) i think your confusing C with C++/Java - C doesnt have operator
> overloading.

Jacob knows this. He probably also thinks it is homework and probably
does not want people to pass courses if they cannot do their homework.

>>> Thanks to all!
>>>
>> You are welcome!
>
> By the way, it isn't homework for those who thought it was.

Well, if it is part of your job and you cannot do it then you should not
have the job. If it is an exercise from a text book you will only get
the benefit from doing it yourself. If it is sample interview questions
and you are practising for an interview and you can't answer those
questions then you are the wrong person for the job.

So now give us a good reason we should do this for you instead of you
doing it and then asking for comments on your answers?
--
Flash Gordon

Daniel

unread,
Nov 20, 2007, 11:13:09 PM11/20/07
to
On Nov 21, 9:28 am, Charlton Wilbur <cwil...@chromatico.net> wrote:

> If you just give us the email of the professor, we can submit your
> homework directly, saving you loads of effort.

http://www.cs.columbia.edu/~pblaer/cs1003/hw3a.html

Its somebodys homework.

Richard Bos

unread,
Nov 21, 2007, 2:35:31 AM11/21/07
to
Flash Gordon <sp...@flash-gordon.me.uk> wrote:

> Haskell Prelude wrote, On 20/11/07 22:45:
> > On 20 Nov 2007 at 22:06, jacob navia wrote:
> >> Haskell Prelude wrote:
> >>> Hello Friends -
> >>>
> >>> Can anyone answer these C questions?

> >>> stack newStack(); /* Creates an empty stack. */
> >> { stack s;
> >> return s;
> >> }

> > 2) i think your confusing C with C++/Java - C doesnt have operator


> > overloading.
>
> Jacob knows this. He probably also thinks it is homework and probably
> does not want people to pass courses if they cannot do their homework.

You think so? I think jacob is writing in a language which is neither C
nor C++ or Java.

Richard

Shadowman

unread,
Nov 21, 2007, 10:02:30 AM11/21/07
to
Oh no? It looks remarkably similar to this page that has "homework"
written at the top and a professor's email at the bottom.

http://www.cs.columbia.edu/~pblaer/cs1003/hw3a.html

--
SM
rot13 for email

Flash Gordon

unread,
Nov 21, 2007, 7:46:08 PM11/21/07
to
Richard Bos wrote, On 21/11/07 07:35:

> Flash Gordon <sp...@flash-gordon.me.uk> wrote:
>
>> Haskell Prelude wrote, On 20/11/07 22:45:
>>> On 20 Nov 2007 at 22:06, jacob navia wrote:
>>>> Haskell Prelude wrote:
>>>>> Hello Friends -
>>>>>
>>>>> Can anyone answer these C questions?
>
>>>>> stack newStack(); /* Creates an empty stack. */
>>>> { stack s;
>>>> return s;
>>>> }
>
>>> 2) i think your confusing C with C++/Java - C doesnt have operator
>>> overloading.
>> Jacob knows this. He probably also thinks it is homework and probably
>> does not want people to pass courses if they cannot do their homework.
>
> You think so?

Yes.

> I think jacob is writing in a language which is neither C
> nor C++ or Java.

Check the other answers that Jacob provided and you will see why I think
Jacob was deliberaltely giving wrong answers rather than giving
lcc-win32 answers.
--
Flash Gordon

Haskell Prelude

unread,
Nov 26, 2007, 2:21:16 PM11/26/07
to
Hey shit-for-brains

What the hell were you thinking here? None of these goddam answers are
right. Why did you post if you don't know a goddam thing about the
subject? It's also incredible that noone else noticed the mistakes and
corrected them.

You're a joke man. This whole newsgroup is a goddam joke man.

On 20 Nov 2007 at 22:06, jacob navia wrote:

Willem

unread,
Nov 26, 2007, 2:40:08 PM11/26/07
to
Flash wrote:
) Richard Bos wrote, On 21/11/07 07:35:
)> I think jacob is writing in a language which is neither C
)> nor C++ or Java.
)
) Check the other answers that Jacob provided and you will see why I think
) Jacob was deliberaltely giving wrong answers rather than giving
) lcc-win32 answers.

Richard didn't say he thought Jacob was giving lcc-win32 answers.
All he said was he thinks it's not C, C++ or Java.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

Charlton Wilbur

unread,
Nov 26, 2007, 2:35:23 PM11/26/07
to
>>>>> "HP" == Haskell Prelude <n...@avalid.email.com> writes:

HP> Hey shit-for-brains What the hell were you thinking here? None
HP> of these goddam answers are right. Why did you post if you
HP> don't know a goddam thing about the subject? It's also
HP> incredible that noone else noticed the mistakes and corrected
HP> them.

He, and we, noticed that this looked an awful lot like homework, and
gave you appropriate answers. One hopes you got an appropriate grade.

HP> You're a joke man. This whole newsgroup is a goddam joke man.

Good luck with your next assignment!

Charlton


--
Charlton Wilbur
cwi...@chromatico.net

Flash Gordon

unread,
Nov 26, 2007, 3:13:34 PM11/26/07
to
Willem wrote, On 26/11/07 19:40:

> Flash wrote:
> ) Richard Bos wrote, On 21/11/07 07:35:
> )> I think jacob is writing in a language which is neither C
> )> nor C++ or Java.
> )
> ) Check the other answers that Jacob provided and you will see why I think
> ) Jacob was deliberaltely giving wrong answers rather than giving
> ) lcc-win32 answers.
>
> Richard didn't say he thought Jacob was giving lcc-win32 answers.
> All he said was he thinks it's not C, C++ or Java.

Replace "lcc-win32" with "some language other than C" then if you want.
I do not believe that Jacob was attempting to provide correct answers
for any language. In fact I believe he was deliberately giving incorrect
answers and if they were correct for *any* language that was mere chance.
--
Flash Gordon

REH

unread,
Nov 26, 2007, 5:44:46 PM11/26/07
to
On Nov 26, 2:21 pm, Haskell Prelude <n...@avalid.email.com> wrote:
> Hey shit-for-brains
>
> What the hell were you thinking here? None of these goddam answers are
> right. Why did you post if you don't know a goddam thing about the
> subject? It's also incredible that noone else noticed the mistakes and
> corrected them.
>
> You're a joke man. This whole newsgroup is a goddam joke man.

God, now *that's* funny. Thanks Jacob!

REH

jacob navia

unread,
Nov 26, 2007, 5:49:00 PM11/26/07
to
Haskell Prelude wrote:
> Hey shit-for-brains
>
> What the hell were you thinking here? None of these goddam answers are
> right. Why did you post if you don't know a goddam thing about the
> subject? It's also incredible that noone else noticed the mistakes and
> corrected them.
>
> You're a joke man. This whole newsgroup is a goddam joke man.
>

You learned something man!

DO NOT TRY TO CHEAT by using this newsgroup!

At least we will not have you around any more!

J. J. Farrell

unread,
Nov 26, 2007, 6:15:20 PM11/26/07
to
Haskell Prelude wrote:
> Hey shit-for-brains
>
> What the hell were you thinking here? None of these goddam answers are
> right.

Good, you noticed.

> Why did you post if you don't know a goddam thing about the
> subject?

That question doesn't make sense. Jacob knows a great deal about the
subject; he answered the way he did to help you learn.

> It's also incredible that noone else noticed the mistakes and
> corrected them.

What on earth makes you think that no-one noticed? The answers were
blatantly and obviously a joke; it's not appropriate to "correct" jokes.

> You're a joke man. This whole newsgroup is a goddam joke man.

Far from it. It's a place for discussion of C, not for doing homework
for lazy cheats. There are plenty of people here who will do consulting
work for you, though, at an appropriate rate of pay.

John Bode

unread,
Nov 27, 2007, 4:47:27 PM11/27/07
to
On Nov 26, 2:21 pm, Haskell Prelude <n...@avalid.email.com> wrote:
> Hey shit-for-brains
>
> What the hell were you thinking here?

And what exactly were you thinking? That nobody here would recognize
what was *obviously* a homework problem? Here's a clue, Bubba; don't
just cut and paste the assignment.

> None of these goddam answers are right.

If you know that much, why did you need to ask for help in the first
place?

> Why did you post if you don't know a goddam thing about the
> subject? It's also incredible that noone else noticed the mistakes and
> corrected them.
>

Jacob knows plenty about the subject, enough to recognize a student
too lazy to do his own homework. You're lucky he got to you first and
posted such obviously ridiculous answers; some of the other regulars
here (myself included) are far less charitable, would have given you
plenty of rope to hang yourself with, and you wouldn't realize it
until it was far too late.

> You're a joke man. This whole newsgroup is a goddam joke man.

The joke is you're the 8,543,981,259th clueless larva who somehow
believes that a bunch of professional programmers can't recognize a
"do my homework for me" post.

Willem

unread,
Nov 27, 2007, 4:50:16 PM11/27/07
to
John wrote:
) On Nov 26, 2:21 pm, Haskell Prelude <n...@avalid.email.com> wrote:
)> None of these goddam answers are right.
)
) If you know that much, why did you need to ask for help in the first
) place?

Maybe he found out because he handed them in. That's might be why he
reacted so pissed off. But I doubt that the universe would be that just.

John Bode

unread,
Nov 27, 2007, 5:19:04 PM11/27/07
to
On Nov 27, 4:50 pm, Willem <wil...@stack.nl> wrote:
> John wrote:
>
> ) On Nov 26, 2:21 pm, Haskell Prelude <n...@avalid.email.com> wrote:
> )> None of these goddam answers are right.
> )
> ) If you know that much, why did you need to ask for help in the first
> ) place?
>
> Maybe he found out because he handed them in. That's might be why he
> reacted so pissed off. But I doubt that the universe would be that just.
>

Oh, that would have been just too damned sweet. That's a level of
cluelessness rarely seen in the wild.

Flash Gordon

unread,
Nov 27, 2007, 5:26:37 PM11/27/07
to
Willem wrote, On 27/11/07 21:50:

> John wrote:
> ) On Nov 26, 2:21 pm, Haskell Prelude <n...@avalid.email.com> wrote:
> )> None of these goddam answers are right.
> )
> ) If you know that much, why did you need to ask for help in the first
> ) place?
>
> Maybe he found out because he handed them in. That's might be why he
> reacted so pissed off. But I doubt that the universe would be that just.

I think that either it did or he missed the deadline for handing in the
homework whilst waiting for us to do it. Either way it will help keep
the number of incompetent programmers down.
--
Flash Gordon

Dik T. Winter

unread,
Nov 27, 2007, 7:07:50 PM11/27/07
to
In article <87k5o42...@mithril.chromatico.net> Charlton Wilbur <cwi...@chromatico.net> writes:
> >>>>> "HP" == Haskell Prelude <n...@avalid.email.com> writes:
>
> HP> Hey shit-for-brains What the hell were you thinking here? None
> HP> of these goddam answers are right. Why did you post if you
> HP> don't know a goddam thing about the subject? It's also
> HP> incredible that noone else noticed the mistakes and corrected
> HP> them.
>
> He, and we, noticed that this looked an awful lot like homework, and
> gave you appropriate answers. One hopes you got an appropriate grade.

Considering his response, I think it was an F.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/

CBFalconer

unread,
Nov 27, 2007, 6:12:44 PM11/27/07
to
John Bode wrote:
> Haskell Prelude <n...@avalid.email.com> wrote:
>
>> Hey shit-for-brains
>>
>> What the hell were you thinking here?
>
> And what exactly were you thinking? That nobody here would
> recognize what was *obviously* a homework problem? Here's a clue,
> Bubba; don't just cut and paste the assignment.
>
>> None of these goddam answers are right.
>
> If you know that much, why did you need to ask for help in the
> first place?
>
... snip ...

>
> The joke is you're the 8,543,981,259th clueless larva who somehow
> believes that a bunch of professional programmers can't recognize
> a "do my homework for me" post.

He didn't know better. He posted the original answer, and Jacob
'answered' almost immediately. He apparently took the result and
passed it in. About a week later he returned here with his
diatribe, probably after getting his paper back with a zero mark.
Jacob did well.

However, it looks as if he hasn't learned much. List him under "Do
not hire under any circumstance".

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

J. J. Farrell

unread,
Nov 27, 2007, 7:32:36 PM11/27/07
to
CBFalconer wrote:
> ...

>
> However, it looks as if he hasn't learned much. List him under "Do
> not hire under any circumstance".

I'm going to have to find a faster algorithm for searching that list ...

Richard Harter

unread,
Nov 27, 2007, 11:59:29 PM11/27/07
to
On Wed, 28 Nov 2007 00:07:50 GMT, "Dik T. Winter"
<Dik.W...@cwi.nl> wrote:

>In article <87k5o42...@mithril.chromatico.net> Charlton Wilbur <cwi...@chromatico.net> writes:
> > >>>>> "HP" == Haskell Prelude <n...@avalid.email.com> writes:
> >
> > HP> Hey shit-for-brains What the hell were you thinking here? None
> > HP> of these goddam answers are right. Why did you post if you
> > HP> don't know a goddam thing about the subject? It's also
> > HP> incredible that noone else noticed the mistakes and corrected
> > HP> them.
> >
> > He, and we, noticed that this looked an awful lot like homework, and
> > gave you appropriate answers. One hopes you got an appropriate grade.
>
>Considering his response, I think it was an F.

{OT] Definitely off topic but afficianados of this sort of thing
might enjoy the following links from my web site:

http://home.tiac.net/~cri_c/letters/2005/let05jan.html#barb/
http://home.tiac.net/~cri/2001/austinbib.html

The internet is not always a reliable source of knowledge.

Richard Harter, c...@tiac.net
http://home.tiac.net/~cri, http://www.varinoma.com
In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die

Philip Potter

unread,
Nov 28, 2007, 4:22:31 AM11/28/07
to

I suggest using a heap. Don't hire anyone from the bottom of the heap.

Phil

CBFalconer

unread,
Nov 28, 2007, 5:15:57 AM11/28/07
to

You can put my hashlib library to work!

Eric Sosman

unread,
Nov 28, 2007, 11:13:07 AM11/28/07
to
Flash Gordon wrote On 11/27/07 17:26,:

It's already below ULONG_MAX, despite appearances.

Getting it below INT_MAX (for all implementations)
would be a challenge. Getting it below INT_MIN would
be a *real* challenge.

--
Eric....@sun.com

Philip Potter

unread,
Nov 28, 2007, 12:01:53 PM11/28/07
to

All it requires is a cast to unsigned long.

Reply all
Reply to author
Forward
0 new messages