C / C ++. The main thing is to start!

One of the main problems of a person who wants to start learning C / C ++ programming languages, while not knowing anything about them, may be the lack of a starting point of support. This article is intended to help beginners take the first steps on an exciting path to mastering this family of languages.

So, before rushing into the deep reaches of the Internet in search of C programming lessons, you need to prepare yourself a good ground - a programming environment. At the moment, there are a considerable number of programs that allow you to write programs in the language in question, check the syntax and compile (translate) the source code of the program into an executable file (with the extension * .exe). Among them, I want to note primarily Borland C, Borland C ++, Dev-C ++, Visual Studio, Eclipse, NetBeans, IDEA. I especially want to consider here the rather old, but still very popular Borland C ++ environment (using the example of version 5.5.1) due to the presence of some difficulties in its configuration (however, it is better to use a more modern and more automated environment, of course).

So, first of all, you need to download the Borland C ++ compiler itself, which is included in the Borland Free Command Line Tools installer package (file freecommandLinetools.exe). After launching the downloaded file, install the proposed compiler, selecting all options by default. Installation will occur in the folder C: \ Borland \ BCC55. Having entered it, among other folders, you can see the Bin folder, inside which there are several executable files. By launching them directly, we make sure that the DOS window (usually black) flashes and disappears immediately. You ask how to have time to do something and, in general, consider what is written. The answer is with the help of the command line integrated into the Windows system. You can call it as follows. Hold down the Win + R key combination on the keyboard and enter three letters in the window that appears - cmd. In order to run programs, located in the mentioned Bin folder, you must first go to the folder on the command line. This is done by typing cd C: \ Borland \ BCC55. To run the program now you only need to enter the name of the program. I must say right away that we need the bcc32.exe file, which is the main program that compiles the C source code into an executable exe file.

In order not to write the cd C: \ Borland \ BCC55 command each time, you must add this path to the so-called Windows PATH variable. Having done this, the system (including the command line) will know about the presence of this path, and then you can restrict yourself to the bcc32.exe command on the command line without specifying the path to this file. So, this is done as follows. When you find the icon or menu "My Computer" on the desktop or in the "START" menu, right-click on it and go to "Properties". Next, enter the additional parameters (Fig. 1) and click on the button "Environment variables ...".

image
Fig. 1.

In the "System Variables" window, find the Path variable and add through ";" at the end of its contents is the path C: \ Borland \ BCC55 \ Bin \ (Fig. 2).

image
Fig. 2.

Next, you need to create two configuration files in the Bin folder (i.e. with the extension * .cfg) - bcc32.cfg and ilink32.cfg.

bcc32.cfg should contain 2 lines:

-I "C: \ Borland \ BCC55 \ Include"
-L "C: \ Borland \ BCC55 \ Lib"

ilink32.cfg should contain 1 line:

-L "C: \ Borland \ BCC55 \ Lib »

In principle, this completes the installation of Borland C ++.

Now let's write traditionally the first program “Hello, World!”. Before you start writing a program directly, you need to know that a C program must be written in a text file with the * .c extension, and a program containing C ++ commands in addition must be written in a text file with the * .cpp extension. So, create a text file named first.txt and replace the extension .txt with .c. We open this file with a notepad (in my opinion, the modernized Notepad ++ notepad is best, because it supports the C / C ++ syntax, highlighting it and highlighting program blocks, which greatly facilitates the visual perception of the code) and write the following lines there:

#include

int main()
{
printf("Hello, World!");
}

Save this file. We go to the command line and write the command bcc32.exe first.c. As a result, the compiler will check the error code and create the executable file first.exe - a program that displays the message “Hello, World!” On the screen (in the same command window).
#Include linetells the compiler to include the stdio.h file (stdio stands for STanDard Input-Output) containing information about most of the basic functions of C. This file and similar files are located in the Include folder. Further, any C program starts its execution with the main function main (), the result of which should be an integer of type int (integer). The body of the function is written in curly brackets - a sequence of commands and operators that are executed in turn. The printf (Print Formatted) function is used to output formatted text to a standard input-output device. After each such function, a semicolon is required.

Now that you are ready to write C programs (when you already know the whole sequence of actions before generating the exe file), you can start using some kind of manual, tutorial or online lessons. I would like to note the wonderful book by Kernigan and Ritchie (in fact, these are the creators of the C language) “Programming in C” (2nd edition, 2009), in which many subtleties of the language are described in an accessible language and with which you can begin to feel the language itself. Good luck and success in your journey!

PS For (greater) responsiveness when writing a program in C / C ++, I highly recommend using the Total Commander (or FAR) file manager. Using this program, you can quickly create new text files with the extension * .c (or * .cpp), call up the command line with one click of a button (instead of going into the START menu each time) and, as a result, quickly complete the compilation of the source code.

Also popular now: