TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

C Tutorials

C Local Variables

Overview

Variables that are declared inside a block or function are known as local variables. The scope and visibility of the local variable are limited to the block or the function in which the variable is defined.

The scope of the variable is a region of the C program where the variable can be referenced or used in the program.

Local Variable

The local variable is stored on the Stack. The lifetime is limited to the block or the function
in which the variable is defined.

They can be used only by the programming statements that are inside that block of code or function. The lifetime of the variable ends when the block or function completes execution.

Example

Following is the example that explains the concepts that we have learned:

/**
*************************************************
 * Program Description:
 * C Local Variable Demo
 * Filename: local.c
 * C Tutorials - www.TestingDocs.com
 ************************************************
 */
#include

int main()
{
 /* local variable of the main function */
 int outer = 10;
 {
 /* local variable of the block */
 int inner = 20;
 printf(" The inner variable is alive inside the block = %d \n",inner);
 printf(" The outer variable is alive & visible in the block = %d \n",outer);
 }
 printf(" The inner variable is dead outside the block. \n");
 printf(" The outer variable is alive & visible in the main() = %d \n",outer);

 return 0;
}

C Local Variables

 

—

C Tutorials

C Programming Tutorials on this website:

https://www.testingdocs.com/c-language-tutorial/

Related Posts

C Language Characteristics

C Tutorials /

C Language Characteristics

C Source Code .c File

C Tutorials /

C Program Files & Formats

GNU Compiler Collection GCC

C Tutorials /

C Compilers

C Pointers

C Tutorials /

C Pointers

C Tutorials /

C Two-Dimensional Arrays

‹ C Constants› C Global Variables

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com