This is a Clilstore unit. You can link all words to dictionaries.

BASICS OF LANGUAGE С/C++

1.1 Basics of programming language С/C++. Alphabet of the language. Data types

 Programming language C was created in 1972 by employee of Bell Laboratories Company (USA) Dennis Ritchie. Before him programming languages ​​A and B were created, but they were not widely used.

Language Cis a high-level language that supports structured programming methodology (like Pascal), but at the same timeithas some characteristics peculiar to the assembler language.

With the language, it is possible to create such system programs as compilers and operating systems. The first system program product developed using the SI became UNIX operating system.

C standard was approved in 1983 by the American National Standards Institute (ANSI) and is called ANSI C. At the beginning of 1980s in the same Bell Laboratories company, its employee Bjarne Stroustrup developed extension of C language that was designed for object-oriented programming. In 1983 the languagegot nameC ++.

Alphabet of language С++ 

All programming languages have their own alphabet. An alphabet is different symbols used in the program (letters, digits, labels, signs). The alphabet of language C ++consists of:

Other signs (for example Russian letters)can be used in comments, lines and symbol constants. Combinations of certain symbols not separated by spaces are interpreted as onesignificant symbol. These include:

++  --   ==   &&   ||  <<>><=   +=  -=  *=   /=    /*  */    //

Comments in language Turbo С are recorded between a pair of symbols /*  */ , and in languageС++ after symbols //  .

For example:  1)      /* Heron's formula */  

2)      //  equality of triangles

Identifiers

The sequence of Latin letters, digits, underline symbolsis called identifier.

For example: x1, esep_1,max, _min,  SUMMA

In contrast to Pascal, in C/C++ uppercase and lowercase letters are differed.

For example: max, Max, MAX, mAX - are different identifiers

Service words

Service (key) words in C – are identifiers, the purpose of which is uniquely defined in language. They can not be used as freely selectable names. Full list of service words depends on implementation of the language, i.e.is different for various compilers. However, there is a constant core, which is defined by the C ++ standard.

For example: auto, break, сase, char, continue, if, goto, void, while, long, unionит.д.

Data types

In C / C ++, there are four basic arithmetic (numeric) data types. Among them, two are integer-valued - char, int, and two are floating (real) - float, double.

Besides, some modifications of these types can be used in programs (see Table1).

 

Table 1.  Data types in languageС++

Data types

Range of values

Size(byte)

1. Integer type
Char
- 128 .. +127
1

Enum

- 32768 .. 32767

1

Int

- 32768 .. 32767

2

unsigned char

0 .. 255

1

unsigned int

0 .. 65535

2

short  int

- 32768 .. 32767

2

unsigned short

0 .. 65535

2

long int

- 2147483648 .. 2147483647

4

Unsigned long int

0..4294967295

4

2. Real type

float

±(3.4 e-38.. 3.4 e+38)

4

double

±(1.7 e-308.. 1.7 e+308)

8

long double

±( 3.4 e – 4932.. 1.1 e+4932)

10

 

Тhe format of the description of the variables in programsC/C++:

name_of the typelist_of variables;

Examples of descriptions:

int  x,y,z;

unsigned long max1,max2;

float a,b,c;

At the same time with description it is possible to set the initial values of variables. Such action is called the initialization of variables.

Description with the initialization is carried out according to the following scheme:

typename_of the variable = initial_value;

For example: int  Sum=0, n=0;

 float  p=1.55 ;

unsignedintx=100, year=2013;

Constants

Integer and numeric constants are recorded as in Pascal. The programmer can clearly set the constant type, using suffixes. There are three types of suffixes: F (f) -float; U (u) -unsigned; L (l) -long (for integer and real constants).

Besides, joint use of suffixes U and L in versions UL or LU is acceptable. For example: 3.14F, 100U, 512345UL

Symbol constants are put in apostrophes.

For example: ‘V’, ’a’, ’1’, ’%’, ’)’

And constant, consisting of symbol lines is enclosed in brackets. For example: “Sum =”,   “Enter digits х, у”.

A special kind of symbols constants are control symbols. Their purpose - to control output on screen. In C program they are represented by a pair of symbols, the first of which is   ‘\’.    Will provide some of control symbols:

‘\n’- wrapping

\t’-  horizontal tab

‘\r’-  moves cursor to the beginning of line

‘\\’-  backslash

‘\’’-  apostrophe

‘\0’-  symbol 0

‘\a’- beeping

‘\b’- backspace

‘\f’-  page brake

‘\v’-  vertical tab

‘\?’-  inquiry character

For example:     “\n Text \n divided into \n 3 lines”

Named constants (constant variables).

To define named constants the service word const is used.

Recording format:  const type_ of constantname_of constant=value;

For example: const float  x=2.55, y=1.22;

const int  min=1, max=100; 

Another possibility to introduce a named constant is use preprocessor directive #define in the following format:  #define

In this case, the above example can be recorded as:

#define  x  2.55

#define  y 1.22 

Note!Do not put the equal sign between the constant name and its value, and do not put semicolon at the end of the directive.

 Enumerators

Enumerators allow to define the sequence of integer named constants. Description of the enumerated type shall begin from the service word enum and the subsequent list of constants shall be enclosed in braces.

For example: enum {one=1,two,three,four};

enum Day {Sunday, Monday,Tuesday};

enum Boolean {Yes,No};

By default, the value for the first constant is zero, all other constants are numbered in the ascending order.

 

 

Short url:   https://multidict.net/cs/6243