Click here to Skip to main content
15,886,045 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
is the answer to this:
What is the value of
temp
after executing the code below? Explain your
answer.
C#
int   temp, values[6]  = {3, 4, 5, 1, 2, 8};
temp =  *(values + 2);



Just 5??

Thanks
Posted
Updated 11-Dec-15 15:38pm
v2
Comments
PIEBALDconsult 11-Dec-15 21:38pm    
Try it.
Is there any issue in this code?
Member 12197225 11-Dec-15 21:49pm    
i did try it and it printed 5, but i was unsure id thats correct
PIEBALDconsult 12-Dec-15 0:02am    
It is. Don't you wish you had said that to begin with?

Yeah, it's 5. But the question YOU have to answer is why. This is your homework assignment, not ours.

The point of the exercise is to see if YOU understand what's going on, not if we do.
 
Share this answer
 
Comments
Member 12197225 11-Dec-15 21:52pm    
Yeh i think i understand it. the Pointer is pointing to the 3 and then adds two? therefore 5?
Dave Kreskowiak 11-Dec-15 21:56pm    
You're thinking in terms of the contents of the array, not the array itself.
Member 12197225 11-Dec-15 22:00pm    
I'm not sure what you mean, sorry?
Is it pointing at the 3rd element (the 5)??
Member 12197225 11-Dec-15 22:03pm    
Got it thanks. But why is the pointer picking a value + 'Random Number'
Dave Kreskowiak 12-Dec-15 0:26am    
Like Solution 2 says, you need to read up on pointers and arrays.
Sounds like you need to read up on arrays and pointers. Have a look at this[^] and see if you can understand it then.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Dec-15 3:29am    
Come to think about, this is the best advice, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900