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

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com