📘 Lesson  ·  Lesson 59

Storage Classes

Storage Classes

What are Storage Classes?

💡 Note

Storage classes define a variable's scope, lifetime and default value.

The Four Classes

ClassMeaning
autodefault for local variables
registersuggest storing in CPU register (fast)
statickeeps value between function calls
externvariable defined in another file

static Example

C
void counter() {
    static int count = 0;   // keeps value
    count++;
    printf("%d ", count);
}
counter(); counter(); counter();   // 1 2 3
Output:
1 2 3

Summary

  • auto = local default; register = fast; static = persists between calls; extern = defined elsewhere.

Storage Classes क्या हैं?

💡 Note

Storage classes variable का scope, lifetime और default value तय करते हैं।

चार Classes

Classमतलब
autolocal variables का default
registerCPU register में रखने का सुझाव (तेज़)
staticfunction calls के बीच value रखता है
externदूसरी file में defined variable

static Example

C
void counter() {
    static int count = 0;   // value रखता है
    count++;
    printf("%d ", count);
}
counter(); counter(); counter();   // 1 2 3
Output:
1 2 3

सारांश

  • auto = local default; register = तेज़; static = calls के बीच रहता; extern = कहीं और defined।
← Back to C Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n