C Programming C++ Java JavaScript Kotlin PHP Python

💻 C Programming

Learn the basics of C programming, including variables, loops, and functions.

Tokens in C

In C, a token is the smallest element of a program that is meaningful to the compiler.
C programs are made up of tokens combined to form statements and expressions.

The types of tokens in C are:

  1. Keywords

  2. Identifiers

  3. Constants

  4. Strings

  5. Operators

  6. Punctuation (Special Symbols)


1. Keywords

Keywords are reserved words that have a predefined meaning in C.
They cannot be used as identifiers (names of variables, functions, etc.).

Examples of C Keywords

int, float, char, return, if, else, for, while, do, switch, case, break, continue, void, const, static

Example in code

int main() { int age = 20; // 'int' is a keyword return 0; // 'return' is a keyword }

2. Identifiers

Identifiers are names given to variables, functions, or user-defined items.
They must follow rules:

  • Start with a letter or underscore (_)

  • Can contain letters, digits, and underscores

  • Case-sensitive (age and Age are different)

  • Cannot be a keyword

Examples

int studentAge; float _salary; char grade;

3. Constants

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

Types of Constants in C

  1. Integer constants10, -5, 100

  2. Floating-point constants3.14, -0.75

  3. Character constants'A', 'z', '1'

  4. String constants"Hello", "C Programming"

Example

#include <stdio.h> int main() { const int DAYS_IN_WEEK = 7; // constant integer printf("Days in a week = %d", DAYS_IN_WEEK); return 0; }

4. Strings

Strings are sequences of characters enclosed in double quotes " ".

Example

#include <stdio.h> int main() { char name[] = "Denis"; // string literal printf("Name: %s", name); return 0; }
  • Strings are stored as arrays of characters ending with a null character \0.


5. Operators

Operators are symbols that perform operations on variables and values.

Types of Operators

TypeExamples
Arithmetic+ - * / %
Relational== != > < >= <=
Logical`&&
Assignment= += -= *= /= %=
Increment/Decrement++ --
Bitwise`&
Conditional?:

Example

#include <stdio.h> int main() { int a = 10, b = 5; int sum = a + b; // Arithmetic operator + int isEqual = (a == b); // Relational operator == int result = (a > b) ? a : b; // Conditional operator ? printf("Sum = %d, Is Equal = %d, Result = %d", sum, isEqual, result); return 0; }

6. Punctuation (Special Symbols)

Punctuation symbols are used to separate statements or group code in C.

Common Punctuation Symbols in C

SymbolUse
;Ends a statement
{ }Defines a block of code
( )Function arguments, precedence
[ ]Array indices
,Separator for multiple items
#Preprocessor directives
"Start/end of string literals
'Start/end of character constants

Example

#include <stdio.h> int main() { int numbers[5] = {1, 2, 3, 4, 5}; // { } used for block/array, ; ends statements printf("First number = %d", numbers[0]); // [ ] used to access array return 0; // ; ends statement }

Summary

Tokens are the building blocks of a C program.
They include:

  • Keywords: Reserved words

  • Identifiers: Names of variables, functions

  • Constants: Fixed values

  • Strings: Sequences of characters

  • Operators: Perform operations

  • Punctuation: Special symbols to structure code

All C programs are built using these fundamental elements.

No quizzes yet

Quizzes to test your knowledge coming soon!

📚 Recent Tutorials

Explore the latest tutorials added to our platform

Code copied to clipboard!