Questions about this topic? Sign up to ask in the talk tab.
Difference between revisions of "Return address"
From NetSec
GertieUbpgdd (Talk | contribs) |
|||
(7 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | + | =Introduction= | |
− | = | + | |
A Return Statement, causes a program to exit the current subroutine, and continue at the next point immediately after the exited subroutine. | A Return Statement, causes a program to exit the current subroutine, and continue at the next point immediately after the exited subroutine. | ||
− | Return addresses are saved usually in the call stack of an [[ | + | Return addresses are saved usually in the call stack of an [[application]]'s [[Process|process]]. The return address itself is the location that the function will return to. |
Return statements in many programming languages allow for functions to specify a return value to be passed back to the function that called it. | Return statements in many programming languages allow for functions to specify a return value to be passed back to the function that called it. | ||
Line 21: | Line 20: | ||
void main() { | void main() { | ||
int foo = examplefunction(5,6); | int foo = examplefunction(5,6); | ||
− | + | /* | |
− | + | This area is the return address of the function | |
− | + | The first time the function is executed. | |
− | + | */ | |
printf("foo: %d", foo); | printf("foo: %d", foo); | ||
} | } |
Latest revision as of 04:39, 2 May 2012
Introduction
A Return Statement, causes a program to exit the current subroutine, and continue at the next point immediately after the exited subroutine. Return addresses are saved usually in the call stack of an application's process. The return address itself is the location that the function will return to.
Return statements in many programming languages allow for functions to specify a return value to be passed back to the function that called it.
Each time a function is called, the address of the next instruction is pushed onto the stack. When the return statement occurs, it pops the return address off the stack and then executes code there.
Examples
Language | Source |
---|---|
C++ | void main() { int foo = examplefunction(5,6); /* This area is the return address of the function The first time the function is executed. */ printf("foo: %d", foo); } int examplefunction(int a, int b){ int Sum = a + b; return Sum; //This is the Return statement. } |