Skip to content

Instantly share code, notes, and snippets.

@tharinduwijewardane
Last active December 30, 2018 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tharinduwijewardane/d70464cee4cf859d69e9c206b7bc5039 to your computer and use it in GitHub Desktop.
Save tharinduwijewardane/d70464cee4cf859d69e9c206b7bc5039 to your computer and use it in GitHub Desktop.
Code sample Java meaning C++ meaning
X x; Declares the variable x of class X. This does not creates an object Creates the object x of class X (on stack)
X x = new X(); Declares variable x and creates and assigns an object Invalid syntax
X* x; Invalid syntax Declares a pointer of type X. Same as declaring a variable in Java
X* x = new X(); Invalid syntax Declares a pointer of type X and assigns an object created (on heap)
X& x = y; Invalid syntax Declares a reference of type X and assigns another object which was previously created. A reference cannot be declared without initializing. The concept of reference does not exist in Java.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment