I am building a website to manage and maintain vehicles belongs to a company. There is a feature to track particular vehicle using smart phone which belongs to the vehicle. All vehicles have a smart phone with internet connection and GPS on. Is there any way to do this using javascript or JQuery?
-
what is it currently outputting? – Clay Dec 25 '15 at 08:16
-
2No difference between `f` and `g`, apart from the name of the local variable `p` vs `y`. Both invoke UB as answered already. Neither bodes with the title of your question `different between & and *?`. – dxiv Dec 25 '15 at 08:18
-
For most cases, `&` is _address of_ and `*` is _value at_. – legends2k Dec 25 '15 at 08:20
-
There should be a close reason for obvious UB, especially when the compiler says something like: *"warning: address of stack memory associated with local variable 'p' returned [-Wreturn-stack-address]"* – user3386109 Dec 25 '15 at 08:41
-
Possible duplicate of [Can a local variable's memory be accessed outside its scope?](http://stackoverflow.com/questions/6441218/can-a-local-variables-memory-be-accessed-outside-its-scope) – Bo Persson Dec 25 '15 at 20:46
1 Answers
first of all, let me tell you, both of your functions invoke undefined behavior as you return
the address of a local variable and you try to use the return
value in the caller.
Once the functions will finish their execution, the local variables will cease to exist and the returned address(es) will become invalid. If you want to have the returned address to remain in scope, you need to define a pointer and allocate dynamic memory to them. Maybe you can have a look at the man page of malloc()
and family to get an idea.
That said, FWIW, the &
is called address-of operator, and the properties are mentioned in chapter §6.5.3.2, C11
standard
The operand of the unary
&
operator shall be either a function designator, the result of a[]
or unary*
operator, or an lvalue that designates an object that is not a bit-field and is not declared with the register storage-class specifier.
and
The unary
&
operator yields the address of its operand. If the operand has type ‘‘type’’, the result has type ‘‘pointer to type’’.
Then, the *
is called indirection operator and the properties are
The operand of the unary
*
operator shall have pointer type. [...]
and
The unary
*
operator denotes indirection. If the operand points to a function, the result is a function designator; if it points to an object, the result is an lvalue designating the object. If the operand has type ‘‘pointer to type’’, the result has type ‘‘type’’. [..]

- 133,132
- 16
- 183
- 261