PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 10, 2022

[FIXED] What does *&Var - 1.0f means?

 July 10, 2022     c++, lcg, linear-algebra, pointers, reference     No comments   

Issue

Working with some tutorial, I met a strange C++ expression:

uint64_t var = ....
return (*&var) - 1.f;

What does this mean? Is it a reference to a pointer? What's the point of substracting 1 from reference? It should be an implementation of the LCG algorithm.


Solution

var is an identifier. It names a variable.

The unary & operator is the addressof operator. The result of addressof operator is a pointer to the object named by its operand. &var is a pointer to the variable var.

The unary * operator is the indirection operator. Given a pointer operand, it indirects through that pointer and the result is an lvalue to the pointed object. It is an inverse of the addressof operator.

When you get the address to an object, and then indirect through that pointer, the resulting value is the object whose address you had taken. Essentially, in this case *&var is an unnecessarily complicated way to write var.

What's the point of substracting 1 from reference?

In this case, the referred value is an integer. The point of subtracting 1.f from an integer is to get a smaller value of floating point type.



Answered By - eerorika
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing