C language basics

M4-R5.1 · Chapter 4: Building IoT applications · 4 min read

Introduction to C language

  • C is a High Level ,general-purpose, procedural programming language developed by Dennis Ritchie at Bell Labs in 1972.
  • It was originally created to build the UNIX operating system
  • since become one of the most widely used languages in the world, often called the "mother of all programming languages" because it serves as the foundation for modern languages like Java, Python, and C++.

C Character set

A character set in C programming is a collection of all the valid characters that a compiler recognizes for forming words, expressions, and numbers

  • Alphabets: a–z and A–Z
  • Digits: 0–9
  • Special symbols: @, #, $, _, -, +, (, ), {, }, [ ], etc.

Tokens in C Language

In C programming, tokens are the smallest individual units of source code that carry meaningful representation to the compiler.

  • 1. Constants Fixed values that do not change during program execution.  e.g. 10, 3.14, 'A'
  • 2. Identifiers Names given to variables, functions, or other entities.  e.g. age, salary, myFunction
  • 3. Variables Named memory locations that store changeable data.  e.g. int age = 25;
  • 4. Keywords 32 reserved words with fixed meaning.  e.g. int, if, while, return
  • 5. Operators Symbols that perform operations.  e.g. +, -, *, /, ==
  • 6. Strings Sequence of characters ending with null '\0'.  e.g. "Hello"

1. Identifiers

  • Identifiers are fundamental concepts in programming that used to identify variables, functions, classes, modules, or other entities in a program.
  • Identifiers are names given to variables, functions, arrays, and other user-defined items.

2.3 Rules for Identifiers

  • Must begin with a letter (a–z, A–Z) or underscore (_).
  • Cannot start with a digit.
  • No spaces or commas allowed.
  • Cannot use keyword names (e.g., int, while).
  • Only underscore _ is allowed as a special character.
  • Case-sensitive: Variable and variable are different.

2.Variables

Variables are containers for storing data values, like numbers and characters.

You can think of a variable as a named box where you keep a value that can be used later.

In C, variables must have a specific type, which tells the program what kind of data the variable can store.

  • int - stores whole numbers (integers), such as 123 or -123
  • float - stores numbers with decimals, such as 19.99 or -19.99
  • char - stores a single character, such as 'a' or 'B'. Characters are surrounded by single quotes

Declaring variables 

Syntax - 

type variableName = value;

Example - 

int myNum = 15;

3. Constants 

Constants are fixed values used in a C program.

These values do not change during the execution of the program.

Constants can be integers, floating-point numbers, characters, or strings

Example :

const int MAX_VALUE = 100;

4. Keywords

  • Keywords are predefined, reserved words in C that have specific meanings and functions within the language .
  • C has a total of 32 keywords.

Keywords in C Language - Complete Explanation

5.Operators 

Operators  are special symbols used to perform operations on variables and values Like addition (+) , subtraction(-) etc

They can be classified into several categories based on the type of operation they perform.

We disscus about operator in detail in next chapter

6. Strings 

In C programming, a string is not a built-in data type but is instead a one-dimensional array of characters terminated by a special null character (\0).

Example

Char str[] = “ computer”;