Some more questions about C

H

Haskell Prelude

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!
 
J

jacob navia

Haskell said:
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
70
*ints + 4 40
*ip + 4 110
*(ints + 4) 40
*(ip + 4) 70
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!
 
E

Eric Sosman

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!
 
C

Charlton Wilbur

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
 
H

Haskell Prelude

Haskell said:
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
70
*ints + 4 40
*ip + 4 110
*(ints + 4) 40
*(ip + 4) 70
20
ip[-2]
20

Thanks m8 - diamond.
{ s += x;
}
{ s -= x;
}
doesn't remove it from the stack. */
{ s+s;
}
{ s+0;}

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


{ 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.
You are welcome!

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

J. J. Farrell

Haskell said:
Hello Friends -

Can anyone answer these C questions?
Yes.

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!
 
F

Flash Gordon

Haskell Prelude wrote, On 20/11/07 22:45:
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.
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?
 
R

Richard Bos

Flash Gordon said:
Haskell Prelude wrote, On 20/11/07 22:45:

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
 
S

Shadowman

Haskell said:
Haskell said:
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
70
*ints + 4 40
*ip + 4 110
*(ints + 4) 40
*(ip + 4) 70
20
ip[-2]
20

Thanks m8 - diamond.
{ s += x;
}
{ s -= x;
}
doesn't remove it from the stack. */
{ s+s;
}
{ s+0;}

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

{ 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.
You are welcome!

By the way, it isn't homework for those who thought it was.
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
 
F

Flash Gordon

Richard Bos wrote, On 21/11/07 07:35:
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.
 
H

Haskell Prelude

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.

Haskell said:
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
70
*ints + 4 40
*ip + 4 110
*(ints + 4) 40
*(ip + 4) 70
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!
 
C

Charlton Wilbur

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



>>> 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!
>>
 
W

Willem

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
 
F

Flash Gordon

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.
 
R

REH

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
 
J

jacob navia

Haskell said:
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. J. Farrell

Haskell said:
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.
Haskell said:
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
70
*ints + 4 40
*ip + 4 110
*(ints + 4) 40
*(ip + 4) 70
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!
 
J

John Bode

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.
 
W

Willem

John 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.


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
 

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,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top