π Why are they important?
Before you write any program in C, you need to name things (like variables, functions, etc.) and also use special reserved words (like int, return, while) to give instructions to the computer.
To do that, you must understand two concepts:
Keywords β special words that C already understands
Identifiers β the names you create
Letβs understand each one step by step.
π Keywords β The Reserved Words of C
Think of keywords like the grammar rules or vocabulary of the C language.
Just like in English you have:
if,but,while,and, etc.
In C, we have:
if,else,return,while,int,float, etc.
These are predefined in the language.
C already knows what these words mean β so you canβt redefine or reuse them.
β You can't do this:
int int = 10; // ERROR: 'int' is a keyword, not allowed as a variable nameπ Complete List of 32 Keywords in C
auto break case char const continue
default do double else enum extern
float for goto if int long
register return short signed sizeof static
struct switch typedef union unsigned void
volatile whileπ You canβt name a variable int or return β they are already reserved for the language.
Here they are, grouped for easier understanding:
ποΈ Data Types
|
|
|
|
|
|
|
π Control Flow
|
|
|
|
|
|
|
|
|
|
|
|
π§° Storage Class
|
|
|
|
π§© Others
|
|
|
|
|
|
|
|
|
π Tip to Remember
π "You can use a keyword, but you canβt name anything with it."
β Allowed:
int a = 5;
if (a > 0) {
return 0;
}β Not allowed:
int return = 10; // return is a keywordπ Identifiers β The Names You Create
An identifier is simply the name you give to:
Variables
Functions
Arrays
Structures
Any user-defined elements
π§ Think of identifiers as labels you put on boxes in your room to remember whatβs inside them.
π¦ Examples of Identifiers
int marks; // 'marks' is an identifier
float weight; // 'weight' is an identifier
void calculate(); // 'calculate' is an identifierEach of these is a name created by you to hold or represent something in the program.
π§βπ« Rules for Naming Identifiers
C has strict rules about how you name things. Letβs break them down:
Rule | Explanation | β Correct | β Wrong |
|---|---|---|---|
Must begin with a letter (A-Z or a-z) or underscore (_) only | Canβt begin with a number |
|
|
Can contain letters, digits, and underscores only | No special characters or spaces |
|
|
Case-sensitive |
|
| β |
Cannot be a keyword | Donβt name variables like |
|
|
π Examples (Valid Identifiers)
int age;
float total_marks;
char Grade;
int _counter;β Examples (Invalid Identifiers)
int 1mark; // starts with digit
int my-name; // hyphen not allowed
int float; // 'float' is a keywordπ§ Best Practices for Identifiers
Use meaningful names:
scoreis better thansUse camelCase or snake_case:
totalMarksβtotal_marksβ
Avoid very short or confusing names like
x1,abc,qwe
π§ͺ Real-World Analogy
Imagine a kitchen:
Keywords are like fixed commands: "Turn on the stove", "Boil water". You can't change what they mean.
Identifiers are like names for your containers: "sugarContainer", "riceBowl". You can name them anything you like (as long as you follow the rules).
<div class="infographic-kwid">
<style>
.infographic-kwid {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--code-bg: #1e1e2e;
--code-text: #d4d4e0;
--kw-color: #5b8def;
--kw-soft: #26385e;
--id-color: #e0a458;
--id-soft: #4a3620;
}
.infographic-kwid[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
--code-bg: #0d0d14;
--code-text: #d4d4e0;
--kw-color: #7aa6f5;
--kw-soft: #26385e;
--id-color: #f0b96e;
--id-soft: #4a3620;
}
.infographic-kwid {
box-sizing: border-box;
max-width: 720px;
margin: 0 auto;
background: var(--paper);
color: var(--ink);
font-family: 'Inter', -apple-system, sans-serif;
padding: 0 clamp(1.25rem, 5vw, 3rem);
}
.infographic-kwid *, .infographic-kwid *::before, .infographic-kwid *::after {
box-sizing: border-box;
}
.infographic-kwid h1 {
font-family: 'Fraunces', Georgia, serif;
font-weight: 600;
font-size: clamp(1.6rem, 4vw, 2.2rem);
margin: 2rem 0 0.25rem;
}
.infographic-kwid .subhead {
color: var(--ink-soft);
font-size: 0.95rem;
margin-bottom: 1.25rem;
}
.infographic-kwid .legend {
display: flex;
gap: 1.25rem;
margin-bottom: 1.5rem;
font-size: 0.85rem;
color: var(--ink-soft);
}
.infographic-kwid .legend-item {
display: flex;
align-items: center;
gap: 0.4rem;
}
.infographic-kwid .legend-dot {
width: 10px;
height: 10px;
border-radius: 50%;
display: inline-block;
}
.infographic-kwid .legend-dot.kw { background: var(--kw-color); }
.infographic-kwid .legend-dot.id { background: var(--id-color); }
.infographic-kwid .tabs {
display: flex;
gap: 0.5rem;
margin-bottom: 1.25rem;
flex-wrap: wrap;
}
.infographic-kwid .tab-btn {
all: unset;
cursor: pointer;
font-size: 0.85rem;
font-weight: 600;
padding: 0.5rem 0.95rem;
border-radius: 20px;
border: 1px solid var(--line);
color: var(--ink-soft);
transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.infographic-kwid .tab-btn:hover {
border-color: var(--accent);
}
.infographic-kwid .tab-btn.is-active {
background: var(--accent);
border-color: var(--accent);
color: #fff;
}
.infographic-kwid .example {
display: none;
}
.infographic-kwid .example.is-active {
display: block;
animation: kwid-fade-in 0.3s ease;
}
@keyframes kwid-fade-in {
from { opacity: 0; transform: translateY(4px); }
to { opacity: 1; transform: translateY(0); }
}
.infographic-kwid .code-panel {
background: var(--code-bg);
color: var(--code-text);
border-radius: 8px;
padding: 1.1rem 1.25rem;
font-family: 'IBM Plex Mono', monospace;
font-size: 0.95rem;
line-height: 1.9;
white-space: pre-wrap;
}
.infographic-kwid .tok {
cursor: pointer;
border-radius: 4px;
padding: 0.05rem 0.2rem;
margin: 0 -0.2rem;
transition: background 0.15s, color 0.15s;
}
.infographic-kwid .tok:hover {
background: rgba(255,255,255,0.08);
}
.infographic-kwid .tok.is-kw {
background: var(--kw-soft);
color: var(--kw-color);
font-weight: 600;
}
.infographic-kwid .tok.is-id {
background: var(--id-soft);
color: var(--id-color);
font-weight: 600;
}
.infographic-kwid .detail-panel {
margin-top: 1rem;
padding: 0.9rem 1.1rem;
background: var(--paper-alt);
border-radius: 8px;
font-size: 0.9rem;
color: var(--ink-soft);
min-height: 2.6rem;
line-height: 1.5;
}
.infographic-kwid .detail-panel strong {
color: var(--ink);
}
.infographic-kwid .detail-panel .tag {
display: inline-block;
font-size: 0.72rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.03em;
padding: 0.1rem 0.5rem;
border-radius: 4px;
margin-right: 0.5rem;
}
.infographic-kwid .detail-panel .tag.kw {
background: var(--kw-soft);
color: var(--kw-color);
}
.infographic-kwid .detail-panel .tag.id {
background: var(--id-soft);
color: var(--id-color);
}
.infographic-kwid .takeaway {
border-top: 1px solid var(--line);
padding: 1.25rem 0 2rem;
font-size: 0.95rem;
color: var(--ink-soft);
margin-top: 1.5rem;
}
.infographic-kwid .takeaway strong {
color: var(--ink);
}
@media (prefers-reduced-motion: reduce) {
.infographic-kwid * {
transition: none !important;
animation: none !important;
}
}
</style>
<h1>π Keyword vs Identifier</h1>
<p class="subhead">Five examples β click any word to check what it is.</p>
<div class="legend">
<span class="legend-item"><span class="legend-dot kw"></span>Keyword (reserved)</span>
<span class="legend-item"><span class="legend-dot id"></span>Identifier (your name)</span>
</div>
<div class="tabs" id="kwid-tabs">
<button class="tab-btn is-active" data-ex="0">1. Declaration</button>
<button class="tab-btn" data-ex="1">2. Char type</button>
<button class="tab-btn" data-ex="2">3. Condition</button>
<button class="tab-btn" data-ex="3">4. Loop</button>
<button class="tab-btn" data-ex="4">5. Function</button>
</div>
<div class="example is-active" data-ex="0">
<div class="code-panel"><span class="tok" data-kind="keyword" data-word="int">int</span> <span class="tok" data-kind="identifier" data-word="score">score</span> = 0;</div>
</div>
<div class="example" data-ex="1">
<div class="code-panel"><span class="tok" data-kind="keyword" data-word="char">char</span> <span class="tok" data-kind="identifier" data-word="grade">grade</span> = 'A';</div>
</div>
<div class="example" data-ex="2">
<div class="code-panel"><span class="tok" data-kind="keyword" data-word="if">if</span> (<span class="tok" data-kind="identifier" data-word="isValid">isValid</span>) <span class="tok" data-kind="keyword" data-word="return">return</span> 1;</div>
</div>
<div class="example" data-ex="3">
<div class="code-panel"><span class="tok" data-kind="keyword" data-word="for">for</span> (<span class="tok" data-kind="keyword" data-word="int">int</span> <span class="tok" data-kind="identifier" data-word="i">i</span> = 0; <span class="tok" data-kind="identifier" data-word="i">i</span> < 10; <span class="tok" data-kind="identifier" data-word="i">i</span>++)</div>
</div>
<div class="example" data-ex="4">
<div class="code-panel"><span class="tok" data-kind="keyword" data-word="void">void</span> <span class="tok" data-kind="identifier" data-word="calculateTotal">calculateTotal</span>()</div>
</div>
<div class="detail-panel" id="kwid-detail">Click any highlighted word above to check if it's a keyword or identifier.</div>
<p class="takeaway"><strong>The rule never changes:</strong> keywords are C's fixed vocabulary β you can't rename them. Identifiers are the names you invent.</p>
</div>
<script>
(function () {
const wrapper = document.currentScript.closest('.infographic-kwid')
|| document.querySelector('.infographic-kwid');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
const tabs = Array.from(wrapper.querySelectorAll('.tab-btn'));
const examples = Array.from(wrapper.querySelectorAll('.example'));
const detail = wrapper.querySelector('#kwid-detail');
function resetDetail() {
detail.innerHTML = "Click any highlighted word above to check if it's a keyword or identifier.";
}
function showExample(index) {
tabs.forEach(t => t.classList.toggle('is-active', t.dataset.ex === String(index)));
examples.forEach(e => e.classList.toggle('is-active', e.dataset.ex === String(index)));
resetDetail();
}
tabs.forEach(tab => {
tab.addEventListener('click', () => showExample(tab.dataset.ex));
});
wrapper.querySelectorAll('.tok').forEach(tok => {
tok.addEventListener('click', () => {
const kind = tok.dataset.kind;
const word = tok.dataset.word;
const container = tok.closest('.code-panel');
container.querySelectorAll('.tok').forEach(t => {
if (t.dataset.word === word) {
t.classList.toggle('is-kw', kind === 'keyword');
t.classList.toggle('is-id', kind === 'identifier');
}
});
if (kind === 'keyword') {
detail.innerHTML = '<span class="tag kw">Keyword</span><strong>' + word + '</strong> is reserved by C β it already has a fixed meaning and can\'t be used as a variable or function name.';
} else {
detail.innerHTML = '<span class="tag id">Identifier</span><strong>' + word + '</strong> is a name the programmer chose β for a variable, function, or other entity.';
}
});
});
})();
</script>
</div>