ELEVATE YOUR BUSINESS WITH

Limitless customization options & Elementor compatibility let anyone create a beautiful website with Valiance.

Scope in C

SELECT * FROM `itio_tutorial_master` WHERE `tutorial_menu`='28' AND `tutorial_submenu`='1655' AND `tutorial_status`=1 LIMIT 1

Scope in C

? Scope in C

Scope in C refers to the visibility and lifetime of variables — i.e., where a variable can be accessed in your code.

There are 4 types of scope in C:


? 1. Block Scope (Local Scope)

Variables declared inside a block (like in functions or {}) are accessible only within that block.

c

() { int x = 10; // x has block scope printf("%d", x);}

  • x is local to myFunction()

  • Cannot be accessed outside the block


? 2. Function Scope

Applies to labels (used with goto) inside a function. Rarely used.

c

void func() { goto label; label: printf("Hello\n");}


? 3. File Scope (Global Scope)

Variables declared outside all functions are global — accessible anywhere in the file after declaration.

c

int count = 0; // global variablevoid display() { printf("%d\n", count); // accessible here}


? 4. Function Prototype Scope

In function declarations:

c

void fun(int a); // `a` is only known inside this declaration

This a only exists for declaration purposes.


? Storage Class Keywords & Scope

KeywordScopeLifetime
autoLocalInside block
registerLocalInside block
staticLocal or globalEntire program (retains value)
externGlobalRefers to external variable


?? Tips

  • ? Keep variables local if possible — it avoids bugs.

  • ? Use static inside functions if you need the value to persist between calls.

  • ? Avoid unnecessary global variables.

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql