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.
- 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.
How to Set Up a Development Environment for C Programming?
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:
If you are interested in how to install Notepad++ on Ubuntu, a Linux distribution, watch the following video.
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.
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.
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.
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.
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.
No comments:
Post a Comment