Is it possible to write a function that returns a pointer? What possible problem could the programmer encounter if the address of a function’s local variable (i.e., pointer) was returned to the calling function?
What will be an ideal response?
Sure, it is possible to return a pointer. If a local variable’s address is returned to the calling function, the variable goes out of scope. The pointer will be pointing at a section of memory that is no longer valid. If another function is called, and new variables are placed on the stack, that pointer would then be pointing at that data.
You might also like to view...
Which one of the following cables is composed of plastic or glass fibers that transmit data at extremely fast speeds?
A) Unshielded twisted-pair (UTP) B) Coaxial C) Twisted-pair D) Fiber-optic
What may happen if the router is compromised?
a. Exposes the external network to scans and attacks b. Threatens the overall security of the network c. Overavailability of network services d. Degraded network performance