Getting Started (Lesson)

Getting Started with C Programming

Welcome to the world of Structured Programming! This chapter will guide you through the process of setting up your development environment and understanding the core tools required to write, compile, and run C programs.

1.1 Understanding the Development Environment

To write C programs, you need two essential tools:

  1. Text Editor: Where you write your code (e.g., VS Code, Sublime Text, Notepad++).
  2. Compiler: A special program that translates your human-readable C code into machine code that the computer can execute (e.g., GCC, Clang).

Recommended IDEs (Integrated Development Environments)

An IDE combines a text editor and compiler into one package:

  • Visual Studio Code (VS Code): Modern, lightweight, and highly customizable.
  • Code::Blocks: A popular choice for beginners with a built-in compiler (MinGW).
  • Dev-C++: A classic, simple IDE for Windows.

1.2 Setting up GCC and VS Code

Step 1: Install a Compiler (MinGW for Windows)

  1. Download the MinGW-w64 installer or MSYS2.
  2. Install the mingw-w64-x86_64-gcc package.
  3. Crucial Step: Add the bin folder (e.g., C:\msys64\mingw64\bin) to your System PATH environment variable.

Step 2: Install Visual Studio Code

  1. Download and install from code.visualstudio.com.
  2. Open VS Code and go to the Extensions view (Ctrl+Shift+X).
  3. Install the "C/C++" extension by Microsoft.

Step 3: Verify Installation

Open your terminal or command prompt and type:

gcc --version

If you see the version information, you are ready to go!


1.3 How a C Program Runs

The life cycle of a C program involves several stages:

  1. Editing: Writing code in a .c file.
  2. Preprocessing: Handling #include and #define directives.
  3. Compilation: Converting C code to Assembly.
  4. Assembly: Converting Assembly to Object code (.obj or .o).
  5. Linking: Combining object code with libraries to create an Executable (.exe).

Basic Command to Compile and Run

If your file is named main.c:

# Compilation
gcc main.c -o myprogram

# Execution
./myprogram

Refer to the Lecture Slides for visual diagrams of the compilation process.

PREVIOUS
Problem Solving using Computer
NEXT
Elements of C