Questions about this topic? Sign up to ask in the talk tab.

Difference between revisions of "Return address"

From NetSec
Jump to: navigation, search
(Examples)
Line 21: Line 21:
 
void main() {
 
void main() {
 
     int foo = examplefunction(5,6);
 
     int foo = examplefunction(5,6);
      
+
     /*
    # This area is the return address of the function
+
    This area is the return address of the function
    # The first time the function is executed.
+
    The first time the function is executed.
     #
+
     */
 
     printf("foo: %d", foo);
 
     printf("foo: %d", foo);
 
}
 
}

Revision as of 00:35, 19 October 2011

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. 
}