Programming language C (I)

the language has achieved a great diffusion in recent years. Through this series of articles with a practical approach based on examples, we present the basics of language.

Elhuyar. Science and Technology

The C language that we will continue to explain in this issue and in the coming years has achieved a great diffusion in recent years, being essential for those who today we immerse ourselves in the world of computer science to know it. Through this series of articles with a practical approach based on examples, we present the basics of language, but some other high-level language (BASIC, PASCAL, FORTRAN, etc.) assuming that structured programming is known and encouraged, that is, the distribution of difficult programs in simpler or functional subprograms.

Next chapters:

  • C basic data
  • C agents and expressions
  • Control structures I
  • Control structures II
  • Functions and macros
  • Data Structures I
  • Data Structures II
  • Characteristics of variables
  • Functions II
  • Pre-compiler and library
  • Entrance and exit
  • C compiler and other languages
  • Applications I
  • Applications II

C characteristics

Language C in 1972 D. It was created by Ritchie within the project that was developing the UNIX operating system in the Bell laboratories of AT T. Although it is originally a system-oriented language (since UNIX was the first programmed system in high-level language) and is also used in application programs, C's most common scope of application is programming for the development of standard packages and programs. Therefore, many editors, database systems, graphics and management packages are developed in C. This is due to:

  • Despite being a very simple language, it is powerful, since with its brief battery of sentences and the library it has, all kinds of problems can be solved easily.
  • Once the programs written in C are compiled, they are very effective, since they are very compact (taking a small piece of memo) and fast.
  • The C language is very interchangeable. Therefore, programs written on a machine with a source language can be transferred and executed without changes. It also favors the market presence of many C compilers.
  • Concepts close to physical resources (general records, bits, input/output device logs, etc.) although it is a high-level language They can be used for your interest for some types of applications (screen and disk handling, among others).
Figure . Phases of program development.

On the other hand, if programmers do not act rigorously, programs can be very cryptic and uninterpretable. On the other hand, the compiler does not prove much.

Therefore, it is difficult to detect and correct errors (for the latter debugger programs help more and more).

Programme development

As already indicated, this C language will be explained by examples that will be tested once translated by Microsoft C compiler. Before starting with the language, remember the phases that appear in figure 1: definition of the problem, design of the algorithm, edition of the source program, compilation, link and finally the test.

Although C is a simple language, remembering the above, it has a large library in which there are input/output procedures, arithmetic and graphic functions and many other routines. In addition, we will promote a distributed compilation that favors structured programming. When using this build type, the programmer will keep your library by saving your object module in it. Consequently, the compilation link scheme to consider is shown in Figure 2.

Figure . Compilation and mooring.

First sentences and program structure

In language C the main program always starts with the word main ().

The interests of audiences and juveniles represent the beginning and the end of the body of a function and all body sentences end with the symbol. In Figure 3 we present a simple program that we will analyze below.

printout

and scanf are the standard library functions that direct output and input (parentheses limit parameters). Within them, %s string is the format and\n end of line indicator. Other formats such as %d decimal format, %c character, %f real format and %e scientific writing are supported.

main () /* first program */{

char [20]; printf
(“Press your name: \n”);
scanf (“%s”, name);
printf (“%s C is learning through reading Elhuyar\n”,
name);}
Figure . Our first program.

[20]

is a sentence of eracence. It defines the name variable as a 20-character table. The data types and their corresponding communications are analyzed in the following number. The character pairs /* and */ delimit a suggestion or comment. Therefore, the person involved will not be compiled.

It should be noted that the compiler distinguishes between case sensitive and case sensitive, and for example, since the name and NAME are different variables, it is recommended to write all the code in lowercase, except the parameterized constants and the new data types, which are usually capitalized.

Once the program is edited, the following steps will be followed until the program is tested.

With Microsoft compiler on a PC:

$msc

program

$ program

Regarding the UNIX Operating System:

$

Program -o. Program c
$

Student Corner

Here we will explain and comment on the questions and proposals of those who follow the course C. To participate write to Elhuyar.

"C programming language"


ELHUYAR KULTUR ELKARTEA
Polygon Asteasuain 14.
Neighborhood Txikierdi.
20170 USURBIL

Gipuzkoa
Babesleak
Eusko Jaurlaritzako Industria, Merkataritza eta Turismo Saila