Keywords in C Programming

🎓 In-Class Lecture: Keywords in C Programming

What are Keywords?
Keywords are reserved words in C that have predefined meanings. You cannot use them as variable or function names.

int age;

Here, int is a keyword indicating that age is an integer.

🚫 Why Can’t You Use Keywords as Names?

int if = 10; // ❌ Invalid: 'if' is a keyword

📋 List of 32 Keywords in C

  • Data Types: int, float, char, double, long, short, signed, unsigned
  • Control Flow: if, else, for, while, do, switch, case, break, continue, default, goto
  • Storage Class: auto, static, register, extern
  • Qualifiers: const, volatile
  • Others: return, sizeof, typedef, struct, union, enum, void

🧪 Sample Code Using Keywords

#include <stdio.h>

int main() {
    int x = 10;
    float y = 20.5;

    if (x < y) {
        printf("x is less than y\n");
    } else {
        printf("x is greater than or equal to y\n");
    }

    return 0;
}

❗ Common Mistakes

int return = 5;     // ❌ Invalid
int returnValue = 5; // ✅ Valid

🧠 Quick Quiz

Which of these are valid variable names?

  • main
  • while ❌ (keyword)
  • userName
  • float ❌ (keyword)

📌 Final Points

  • There are 32 keywords in ANSI C.
  • They define the language structure.
  • You cannot use them for identifiers.

📝 Homework

  1. Write a program using at least 5 keywords.
  2. Pick 10 keywords and explain their roles in your own words.

একটি মন্তব্য পোস্ট করুন