Introduction to C Programming: The Very Basics

C is one of the most powerful and widely used programming languages. Before we dive into coding, let’s understand some fundamental concepts.

What is a Program?

A program is a set of instructions that a computer executes to perform a specific task. These instructions are written in a programming language and converted into machine code that the hardware understands. Think of it as a recipe—each step tells the computer what to do, just like a recipe tells a cook how to prepare a dish.

Hardware, Machine Language, Assembly, and High-Level Languages

Computers operate using hardware, which includes components like the CPU, memory, and storage devices. However, hardware only understands machine language, a series of binary codes (0s and 1s). Writing programs in machine language is incredibly difficult for humans.

To make programming easier, assembly language was introduced. It uses mnemonics (short commands like ADD, SUB, MOV) that correspond to machine instructions. Still, writing programs in assembly is complex.

To further simplify programming, high-level languages like C were developed. These languages use English-like syntax and are easier to read and write. A compiler translates high-level language code into machine code.

Structure of a C Program

#include <stdio.h> // Header file

int main() { // main function
printf(“Hello, World!”); // Output statement
return 0; // Return statement
}

  • Header File (#include <stdio.h>): Used to include standard functions like printf().
  • Main Function (main()): Every C program starts execution from this function.
  • Curly Braces {}: Define the block of code.
  • Statements (printf("Hello, World!");): Perform actions.
  • Return Statement (return 0;): Ends the program.

Variables and Identifiers

A variable is a named memory location that stores data.

  • Identifiers are names given to variables, functions, and other elements.

Rules for Variable Names

  • Can contain letters, digits, and underscores (_).
  • Must begin with a letter or _ (Underscore).
  • Cannot start with a digit (e.g., 1num is invalid).
  • Cannot be a keyword (int, return, etc.).
  • Case-sensitive (age and Age are different).

Valid variable names: age,  num_1count123
Invalid names: 123varint,  float-value

Keywords and Data Types in C

  • Keywords are reserved words with special meanings (e.g., int, float, return).
  • Data Types define the type of data a variable can store
    • int – Integer type
    • float – Floating point type or decimal type
    • char – Character type

printf() Function

Used to display output on the screen:

printf(“Welcome to C Programming!”);

Tokens in C

Tokens are the smallest elements in a C program, including:

  • Keywords (int, return)
  • Identifiers (Variable names)
  • Constants (10, 'A')
  • Operators (+, -, *)
  • Special Symbols ({}, [], #

Reserved Keywords in C

C has 32 reserved keywords, including int, char, void, return, if, else, switch, for, while, and do.

(Don’t worry about remembering all of them now—we will learn each in upcoming lessons.)

Conclusion

This was just a basic introduction to C programming. In upcoming lessons, we will explore each concept in detail. Stay tuned

Leave a Comment

Your email address will not be published.