How is return address specified in Stack? Last Updated : 13 Sep, 2022 Comments Improve Suggest changes Like Article Like Report Stack: A stack is a linear data structure in which elements are accessed with one end called the "top" of the stack. It follows the LIFO (Last In First Out) approach. Program Counter: The program counter is a special purpose register in the CPU which stores the memory location of the next instruction. Note: The article uses the abbreviated form "PC" in place of Program Counter. Stack Pointer: A stack pointer is a special register in the CPU which is used to store the address of the top element of the stack. When and how the return address is specified in the Stack?The return address is specified in the stack when a program contains a function call or subroutine.When the function is called then, after its complete execution it has to return back to the original program i.e., the next instruction after the function call in the program.When the function call is to be executed then, the program counter PC holds the address of the next instruction after the function call in the program.For executing the function, the control has to go to the function definition and after executing the function it has to return to the next instruction after the function call in the program.So, when the function is to be executed then, the PC value i.e., the next instruction address is stored onto the stack (SP incremented) and the PC is updated by the address where the function is stored.After the complete execution of the function, the PC gets updated by the return address present in the stack (value at the top of the stack).Example: Assume I3 is the function call instruction and CPU is currently executing I3 and PC = 304. The PC value 304 is stored onto the stack and stack pointer SP is incremented by one. The PC value is updated by 400 i.e., the address where the function is stored. After complete execution of the function PC value is again updated by stack value (top of stack) and stack pointer SP is decremented by 1. Follow the below image for a better idea Example showing storing of return address Comment More infoAdvertise with us Next Article Difference between Stack and Array A aayushi2402 Follow Improve Article Tags : Stack DSA Memory Management Practice Tags : Stack Similar Reads How to Reverse a Stack using Recursion Write a program to reverse a stack using recursion, without using any loop.Example: Input: elements present in stack from top to bottom 4 3 2 1Output: 1 2 3 4Input: elements present in stack from top to bottom 1 2 3Output: 3 2 1The idea of the solution is to hold all values in Function Call Stack un 4 min read Difference between Stack and Array Stack: A stack is a linear data structure in which elements can be inserted and deleted only from one side of the list, called the top. A stack follows the LIFO (Last In First Out) principle, i.e., the element inserted at the last is the first element to come out. The insertion of an element into a 3 min read Difference between Stack and Array Stack: A stack is a linear data structure in which elements can be inserted and deleted only from one side of the list, called the top. A stack follows the LIFO (Last In First Out) principle, i.e., the element inserted at the last is the first element to come out. The insertion of an element into a 3 min read Address Operator & in C The Address Operator in C is a special unary operator that returns the address of a variable. It is denoted as the Ampersand Symbol ( & ). This operator returns an integer value which is the address of its operand in the memory. We can use the address operator (&) with any kind of variables, 3 min read Address Operator & in C The Address Operator in C is a special unary operator that returns the address of a variable. It is denoted as the Ampersand Symbol ( & ). This operator returns an integer value which is the address of its operand in the memory. We can use the address operator (&) with any kind of variables, 3 min read How can the stack memory be increased? A Stack is a temporary memory address space that is used to hold arguments and automatic variables during the invocation of a subprogram or function reference. The size of this stack is called the stack size. Stack â¤â¤ Heap BSS DATA TEXT How to increase stack size? One cannot increase the stack size. 2 min read Like