Click to See Complete Forum and Search --> : Debug 2!
Klashe
01-12-2001, 03:41 PM
Hey all, this isn't really a debug question, but it's in the same vein.
You know 'em, you love 'em. They are pointers. See if you can answer these simple questions about 'em:
Based on the following declarations:
int i=3;
int j=5;
int *p = &i;
int *q = &j;
determine the values for each of the following expressions. Consider each expression independent.
A) p==&i
B) * (* (& p ))
C) ((7 * (* p)) / (* q)) + 7
D) ((7 * (* p)))/*q+7
One answer per person please!
------------------
If I rest, then I rust.
--Indian Proverb
drob8
01-12-2001, 08:51 PM
I hate pointers...besides, shouldn't you be working?
Originally posted by Klashe:
Hey all, this isn't really a debug question, but it's in the same vein.
You know 'em, you love 'em. They are pointers. See if you can answer these simple questions about 'em:
Based on the following declarations:
int i=3;
int j=5;
int *p = &i;
int *q = &j;
determine the values for each of the following expressions. Consider each expression independent.
A) p==&i
B) * (* (& p ))
C) ((7 * (* p)) / (* q)) + 7
D) ((7 * (* p)))/*q+7
One answer per person please!
Grizzly
01-13-2001, 12:34 PM
Alright, Im not entirely confident about these but here's my shot:
A) p==&i
---------answer: value in P is the "address" (memory location) of i. THe exact value could be anything.
B) * (* (& p ))
--------answer: 3
C) ((7 * (* p)) / (* q)) + 7
--------answer: 11
D) ((7 * (* p)))/*q+7
--------answer: 1
Am I wrong? Am I wrong? Am I wrong? http://www.sharkyforums.com/ubb/tongue.gif
Klashe
01-13-2001, 03:49 PM
Originally posted by Grizzly:
Alright, Im not entirely confident about these but here's my shot:
A) p==&i
---------answer: value in P is the "address" (memory location) of i. THe exact value could be anything.
Am I wrong? Am I wrong? Am I wrong? http://www.sharkyforums.com/ubb/tongue.gif
I'll just answer A for you. We'll let other people answer the other three.
Yes, you are wrong. You are not reading the question correctly. I knew this would throw some people off. http://www.sharkyforums.com/ubb/smile.gif Maybe I should rewrite it:
p == &i
------------------
If I rest, then I rust.
--Indian Proverb
Grizzly
01-13-2001, 03:55 PM
Originally posted by Klashe:
I'll just answer A for you. We'll let other people answer the other three.
Yes, you are wrong. You are not reading the question correctly. I knew this would throw some people off. http://www.sharkyforums.com/ubb/smile.gif Maybe I should rewrite it:
p == &i
Ooooh my fault! That was a test for equality, not an assignment operator. Answer is '1', or 'true'.
Klashe
01-13-2001, 04:03 PM
Originally posted by Grizzly:
Ooooh my fault! That was a test for equality, not an assignment operator. Answer is '1', or 'true'.
There you go!
------------------
If I rest, then I rust.
--Indian Proverb
Grizzly
01-13-2001, 09:01 PM
Originally posted by Klashe:
There you go!
Was I correct on the rest of the answers?
Klashe
01-15-2001, 12:17 PM
Originally posted by Grizzly:
Was I correct on the rest of the answers?
Well, since no one else in answering, I'll give you the rest of the answers.
B) correct. when a & and a * are coupled together they are complimentary so they cancel each other out. so essiantially the question is *p which just accesses the value of &i which is 3.
C) correct
D)incorrect. kind of a trick question. Look at it carefully. (Hint: pay attention to the spaces! http://www.sharkyforums.com/ubb/wink.gif )
------------------
If I rest, then I rust.
--Indian Proverb
Grizzly
01-16-2001, 02:05 AM
Originally posted by Klashe:
Well, since no one else in answering, I'll give you the rest of the answers.
B) correct. when a & and a * are coupled together they are complimentary so they cancel each other out. so essiantially the question is *p which just accesses the value of &i which is 3.
C) correct
D)incorrect. kind of a trick question. Look at it carefully. (Hint: pay attention to the spaces! http://www.sharkyforums.com/ubb/wink.gif )
Ooooh, actually isn't the answer to C & D the same? 11 ?
ugh, reminds me of school. I try to stay away from those types of things. http://www.sharkyforums.com/ubb/wink.gif I havent seen that since my first few CS classes.
------------------
"You know, I have one simple request, and that is to have sharks with frickin laser beams attached to their heads. Is that too much to ask?"
Klashe
01-16-2001, 11:44 AM
Originally posted by Grizzly:
Ooooh, actually isn't the answer to C & D the same? 11 ?
Nope, look at it closer. What does /* represent in C?
------------------
If I rest, then I rust.
--Indian Proverb
Klashe
01-16-2001, 11:45 AM
Originally posted by Sol:
ugh, reminds me of school. I try to stay away from those types of things. http://www.sharkyforums.com/ubb/wink.gif I havent seen that since my first few CS classes.
Yeah, I know. But we got to get some kind of programming questions out in this forum! http://www.sharkyforums.com/ubb/smile.gif
------------------
If I rest, then I rust.
--Indian Proverb
Grizzly
01-17-2001, 02:56 AM
Originally posted by Klashe:
Nope, look at it closer. What does /* represent in C?
OH GOD!!! I can't believe I missed that one!! hahahahah, that's a *damn* good one Klashe! Friggin comments!
[This message has been edited by Grizzly (edited January 17, 2001).]