This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

what is dereference?

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This example is from Whizlabs. This code wont compile. The reason they have given is at line 1 we are attempting to dereference the primitive type float. I even heard "deference" word first time. Can anyone please help me?
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know one such term 'dereferencing' with respect to 'C'/'C++' Pointers, which actually means 'taking out the value stored in a particular memory address being pointed to by this pointer value'.

If, p is a pointer to an integer and it can be used as follows.



Here, they would have meant to say the same 'unboxing' i think. As, boxing and unboxing are the means to convert your primitive to wrappers and vice versa.

does that help dolly shah?
[ October 08, 2007: Message edited by: Raghavan Muthu ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Variables do not hold objects. Instead, variables hold references to objects.

So myVariable is just a reference -- not the object itself. But in order to call a method, we need the actual object. The dot operator "dereferences" the variable and "gets" the object.

However, a primitive variable holds the actual value. It does not just reference it. Therefore, primitive variables cannot be dereferenced. So if you try to use the dot operator on a primitive variable, you will get the "cannot be dereferenced" error.
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks marc. I did not know this before.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic