|
-
Katana Wielding Moderator
Debug 2!
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
-
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!
-
Ursus Arctos Moderatis
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?
-
Katana Wielding Moderator
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?
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. Maybe I should rewrite it:
p == &i
------------------
If I rest, then I rust.
--Indian Proverb
-
Ursus Arctos Moderatis
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. 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'.
-
Katana Wielding Moderator
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
-
Ursus Arctos Moderatis
Originally posted by Klashe:
There you go!
Was I correct on the rest of the answers?
-
Katana Wielding Moderator
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! )
------------------
If I rest, then I rust.
--Indian Proverb
-
Ursus Arctos Moderatis
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! )
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. 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?"
Icna tpye 300 wrdos per mnieut
-
Katana Wielding Moderator
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
-
Katana Wielding Moderator
Originally posted by Sol:
ugh, reminds me of school. I try to stay away from those types of things. 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! 
------------------
If I rest, then I rust.
--Indian Proverb
-
Ursus Arctos Moderatis
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).]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|