Monday, February 17, 2025

Learn C Programming Language, A Practical Guide

Although C programming language is no longer as dominant as it once was, it still has its strong application in systems programming, embedded systems, operating systems, and performance-critical applications. The Python programming language has taken over the lead in education due to its simplicity, but C remains irreplaceable in areas where direct control over hardware is needed. Known for its efficiency and flexibility, C is the foundation of many modern programming languages, including C++, Java, and Python. Whether you are a beginner who wants to start with programming or an experienced programmer who wants to deepen your understanding of low-level computing, learning the C language is an excellent choice. This C tutorial and practical guide will help you understand the basics of C programming, covering everything from setting up a development environment to writing and compiling C programs.

The C programming language is a general-purpose procedural language. It is not at all difficult as it is said, because it is only a set of correctly written instructions that the computer will execute. It was created in Bell Laboratories in New Jersey. Its creator, Dennis Ritchie, originally designed and implemented it for the UNIX operating system on a DEC PDP-11 computer, with the aim of replacing assembly language in solving systems programming. Despite the fact that it is generally rarely used today, its extension and successor is the C++ programming language, because unlike the C programming language, it supports object-oriented programming. However, before you step into the C++ programming language, we think you should first learn the C programming language. It is fully accepted by the C++ programming language, so it will also be much easier for you to learn and program in C++ afterwards.

The C programming language is often taught through Linux, especially at universities and technical school

The C programming language is often taught through Linux, especially at universities and technical school

Today, the C programming language is often taught through the Linux operating system more than through Windows or other operating systems, especially in universities and technical schools. The reasons for this are:
  • Natural environment for C – The Linux kernel is written in C, which makes it ideal for learning systems programming.
  • GCC and open-source tools – The GCC compiler and tools like gdb, make, and valgrind are standard in the Linux environment.
  • Terminal-based approach – Linux encourages working through the command line, which allows for a better understanding of compiling, linking, and running programs.
  • Learning programming while working with system resources – Students often learn how to manage memory, processes, and files in a Linux environment.
However, in a corporate environment, Windows is still used for C programming, especially in combination with the Microsoft Visual Studio environment.

How to Set Up a Development Environment for C Programming?

If you are using the Linux operating system, then GCC - GNU Compiler Collection is the most commonly used C compiler on Linux. You can install it using the package manager of your Linux distribution. Currently, as we are writing this text, GCC is already installed by default on Ubuntu 24.04 version:

manuel@manuel:~$ gcc --version

gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0

Copyright (C) 2023 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Regarding the Windows operating system, you can download and install MinGW - Minimalist GNU for Windows or Cygwin, which allow you to use the GCC compiler on Windows. You can also use Microsoft Visual Studio, which comes with its own C compiler, MSVC - Microsoft Visual C++ Compiler. If you want to code with the C programming language in Visual Studio Code on Windows, it is necessary to have MinGW installed and configured, then to select one of the offered extensions such as Code Runner. If you don't know how to install the latest version of MinGW on the Windows operating system, watch the following video:


Windows - 12. - How to install Notepad++ ?

If you are interested in how to install Notepad++ on Ubuntu, a Linux distribution, watch the following video.


Linux - 13. - How to install Notepad++ ?

There are many other IDEs for coding the C programming language. For example, one of the most popular for a long time was Code Blocks.


Windows - 14. How to install Code Blocks?


V4 - Linux - 15. How to install Code Blocks?

In principle, when you have GCC installed in the operating system, you can use any text editor to write C code. For example, even in VI - the hacker's editor.


Windows - 31. How to install VIM on Windows?

As for us, we will use VSCode and Ubuntu, a Linux distribution, for this tutorial. If you don't know how to install VSCode on the Ubuntu Linux distribution, watch the following video.


Linux - 2. How to install Visual Studio Code and .NET Core 7.0 ?

But if you want to use the Windows operating system, watch the following video on how to install Visual Studio Code on the Windows10 operating system.


Windows - 1. How to install Visual Studio Code & .Net Core 7.0 ?

Writing Your First C Program

If you are using Ubuntu, a Linux distribution like us, as we have already mentioned, you don't need to install the GCC compiler, it is installed by default in Ubuntu. Once you have set up the environment, you can write C code. Open the terminal and type the following code:

manuel@manuel-virtual-machine:~$ sudo apt-get update

manuel@manuel-virtual-machine:~$ sudo apt-get upgrade

manuel@manuel-virtual-machine:~$ clear

manuel@manuel-virtual-machine:~$ ls

manuel@manuel-virtual-machine:~$ mkdir tutorials

manuel@manuel-virtual-machine:~$ cd tutorials

manuel@manuel-virtual-machine:/tutorials$ mkdir c_tutorial

manuel@manuel-virtual-machine:/tutorials$ cd c_tutorial

manuel@manuel-virtual-machine:/tutorials/c_tutorial$ code .

When you open Visual Studio Code, it will already have the c_tutorial folder selected. Go to Extensions and install the Code Runner extension. It is necessary to adjust Visual Studio Code for coding in the C programming language. Once you do that, create a new file in your project and name it helloworld.c Then enter the following C programming code.

#include <stdio.h>

int main() {

    printf("Hello, World!\n");

    return 0;

}

Click on the icon in the top right corner, Run Code, and the C code will execute, and you will get the following result:

[Running] cd "d:\tutorials\c_tutorials\" && gcc helloworld.c -o helloworld && "d:\tutorials\c_tutorials\"helloworld

Hello, World!

[Done] exited with code=0 in 4.167 seconds

As you can see, our C code consists of a few lines of code or instructions that essentially mean:

#include <stdio.h> – Includes the standard input/output library.

int main() – The main function where program execution begins.

printf("Hello, World!\n"); – Prints text to the console.

return 0; – Indicates successful program execution.

You can also watch the following video to see what coding your first program in the C programming language looks like.


C Tutorial - 1. How to start with C programming language in 2025?











 

No comments:

Post a Comment