CRYPTO NEWS

CoinSmart Is on the Hunt to Buy Distressed Crypto Assets


The recent market crash is the latest in global financial events that have created unique opportunities for buyers like CoinSmart and FTX wanting to acquire distressed crypto firms at a bargain valuation. (Read More)

Regarding storage and memory key word

Recently I was going through https://docs.soliditylang.org/en/v0.8.13/types.html#data-location-and-assignment-behaviour which explains the data locations and its behaviour.. there in the given code example I have come across function g(uint[] storage) internal pure {} function h(uint[] memory) public pure {} // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.5.0 <0.9.0; contract C { // The data location of x is storage. //::Listen

Recently I was going through

https://docs.soliditylang.org/en/v0.8.13/types.html#data-location-and-assignment-behaviour

which explains the data locations and its behaviour..

there in the given code example I have come across

function g(uint[] storage) internal pure {}

function h(uint[] memory) public pure {}

// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.5.0 <0.9.0;  contract C {     // The data location of x is storage.     // This is the only place where the     // data location can be omitted.     uint[] x;      // The data location of memoryArray is memory.     function f(uint[] memory memoryArray) public {         x = memoryArray; // works, copies the whole array to storage         uint[] storage y = x; // works, assigns a pointer, data location of y is storage         y[7]; // fine, returns the 8th element         y.pop(); // fine, modifies x through y         delete x; // fine, clears the array, also modifies y         // The following does not work; it would need to create a new temporary /         // unnamed array in storage, but storage is "statically" allocated:         // y = memoryArray;         // This does not work either, since it would "reset" the pointer, but there         // is no sensible location it could point to.         // delete y;         g(x); // calls g, handing over a reference to x         h(x); // calls h and creates an independent, temporary copy in memory     }      function g(uint[] storage) internal pure {}     function h(uint[] memory) public pure {} } 

I would like to understand why do we need to pass a state variable as storage or memory in contract functions, when it is alraedy globally availble in the same contract.

CoinSmart Is on the Hunt to Buy Distressed Crypto Assets

Shopping cart
There are no products in the cart!
Continue shopping
0