The C Character Set is the set of all valid characters you can use in a C program. This includes:
+ - * / % & # ! ? , ; : . ( ) { } [ ] _ etc.\n), Tab (\t)A token is the smallest individual unit in a C program. A line of code is made up of multiple tokens. The main tokens are:
;, ,)int, if, else, while, return). You cannot use them as variable names.sum, myVariable, main).
_). Can be followed by letters, underscores, or digits. Case-sensitive (age and Age are different).Constants are values that do not change during program execution.
10, -5, 03.14, -0.005'a', '5', '' (single quotes)"Hello" (double quotes)You can give a name to a constant using the #define preprocessor directive. This makes code more readable and easier to maintain.
#include// This is a symbolic constant #define PI 3.14159 int main() { float area = PI * 5 * 5; // Compiler replaces PI with 3.14159 return 0; }
A variable is a named location in memory used to store data. Its value can be changed during program execution.
You must declare a variable before using it. This tells the compiler the variable's type and name.
int age; // Declares a variable 'age' of type int float marks; // Declares a variable 'marks' of type float char grade; // Declares a variable 'grade' of type char
You assign a value using the assignment operator (=). This can be done at declaration (initialization) or later.
// Initialization int age = 20; // Assignment float marks; marks = 95.5;
Data types define the type and size of data a variable can store.
| Data Type | Keyword | Typical Size (bytes) | Description |
|---|---|---|---|
| Integer | int | 2 or 4 | Stores whole numbers (e.g., 5, -10). |
| Character | char | 1 | Stores a single character (e.g., 'a', ''). |
| Floating Point | float |
4 | Stores single-precision numbers with decimals (e.g., 3.14). |
| Double | double |
8 | Stores double-precision numbers with decimals. |
| No Type | void |
N/A | Used for functions that return nothing. |
An expression is a combination of variables, constants, and operators that evaluates to a single value (e.g., a + 5 * b).
Used for mathematical calculations.
+ (Addition), - (Subtraction), * (Multiplication), / (Division)% (Modulus): Gives the remainder of a division. (e.g., 10 % 3 is 1).Used to compare two values. They return 1 (true) or 0 (false).
== (Equal to)!= (Not equal to)> (Greater than), < (Less than)>= (Greater than or equal to), <= (Less than or equal to)Used to combine two or more conditions.
&& (Logical AND): True only if both conditions are true.|| (Logical OR): True if at least one condition is true.! (Logical NOT): Reverses the truth value (true becomes false, false becomes true).Used to assign values to variables.
= (Simple assignment): a = 10;a += 5 (same as a = a + 5). Also -=, *=, /=.++ (Increment): Increases value by 1.-- (Decrement): Decreases value by 1.++x): Increments first, then uses the value.x++): Uses the value first, then increments.A shorthand for an if-else statement.
(condition) ? value_if_true : value_if_false;
int a = 10, b = 20; int max = (a > b) ? a : b; // 'max' will be 20
These are combinations of variables, constants, and arithmetic operators. C follows operator precedence (like BODMAS) to evaluate them. (e.g., * and / have higher precedence than + and -).