Keywords, Identifiers, Constants, and Variables in C Programming


This tutorial covers the fundamental building blocks of the C programming language, including keywords, identifiers, constants, and variables. It explains their purpose, rules, syntax, and usage with clear examples, helping beginners understand how data is declared, named, stored, and used in C programs.

Keywords, Identifiers, Constants, and Variables in C

1. Keywords in C

Keywords are reserved words with predefined meanings in C. They cannot be used as identifiers.

Example keywords:


int, float, char, if, else, for, while, return, void, static, const

Example:


int number = 10;
return 0;

2. Identifiers in C

Identifiers are names used for variables, functions, arrays, and other program elements.

Rules:

  1. Must begin with a letter or underscore
  2. Can include letters, digits, and underscores
  3. Cannot be a keyword
  4. No spaces allowed

Example:


int totalMarks;
float _average;

3. Constants in C

Constants are fixed values that do not change during program execution.

Types:

  1. Integer: 10, -5
  2. Float: 3.14, 2.5
  3. Character: 'A'
  4. String: "Hello"

Using const:


const int MAX = 100;

Using #define:


#define PI 3.14

4. Variables in C

Variables store data that can change during program execution.

Declaration:


int count;
float price;
char grade;

Initialization:


int count = 5;
float price = 250.75;
char grade = 'A';

Example Program


#include <stdio.h>

int main() {
int age = 30;
float salary = 50000.50;
char grade = 'B';

printf("Age: %d\n", age);
printf("Salary: %.2f\n", salary);
printf("Grade: %c\n", grade);

return 0;
}