DEV Community

Cover image for Язык программирования Си. Глава(Chapter) 6
Amirshokh
Amirshokh

Posted on • Edited on

Язык программирования Си. Глава(Chapter) 6

1. Условный цикл с предусловием(Entry-Condition Loop) while, с постусловием(Exit-Condition Loop) do while и гибкий цикл forкомбинирующий инициализацию(Initialization), условие(Condition) и итерацию(Iteration).
Отличие цикла с предусловием и с постусловием в том, что в случае, когда условие изначально, с самого первого раза оказывается ложным цикл с предусловием опускает выполнение тела, в то время как цикл с постусловием выполнит тело хотя бы один раз так как проверяет условие после выполнения тела.

while(0) printf("Hello!"); //Hello won't be printed
do printf("Hi!"); while(0); //Hi will be printed
Enter fullscreen mode Exit fullscreen mode

2. Неопределённый или зависящий от переменной цикл(Indefinite Loop), цикл со счётчиком(Counting Loop), бесконечный цикл(Infinite Loop) и вложенные циклы(Nested Loops).

while (count < strlen(str)) { statements } //indefinite loop
while (count < num) { statements; count++; } //counting loop
do { statements } while (true); //infinite loop
for (;;) { statements } //also an infinite loop

//nested loops
for (int i = 0; i < n; i++) //outer loop
    for (int j = 0; j < n; j++) //inner loop
        statements;
Enter fullscreen mode Exit fullscreen mode

3. Функции fabs(), pow() и sqrt() в math.h.

//definition of absolute value using functions
printf("%d", fabs(num) == sqrt(pow(num, 2))); 
Enter fullscreen mode Exit fullscreen mode

4. Зарезервированный идентификатор типа _Bool и заголовочный файл stdbool.h с определёнными ключевыми словами bool вместо _Bool, true и false. Истина(Truth) в Си, то есть значение true — это любое ненулевое значение, а ложь — любое нулевое значение 0, '\0' или NULL.

5. Дополнительные операторы:

  • Относительные операторы(Relational Operators): <, >, <=, >=, ==, !=(not_eq в iso646.h).
  • Операторы составного присваивания(Compound Assignment Operators): +=, -=, *=, /=, %=, <<=, >>=, ^=, &=, |=.
  • Оператор запятая(Comma Operator) является точкой следования(Sequence Point).

6. Хранение смежных(Contiguous) массивов и индекс(Subscript) или смещение(Offset) массива.

  1. Функции с возвращаемым значением(Functions with Return Values) и предварительное объявление(Forward Declaration) в заголовочных файлах(Header File).

  2. Представление программы в виде псевдокода(Pseudocode).

Язык программирования Си 6 издание. Стивен Прата
C Primer Plus 6th edition. Stephen Prata

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay