DEV Community

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

Posted on • Edited on

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

1. Массивы(Arrays), Символьные строки(Character String) и нулевой символ(Null Character) '\0'.
Computer memory

2. Библиотека string.h и одна из её функций strlen().

char str[10] = "Hello!";
printf("%zu", strlen(str));
Enter fullscreen mode Exit fullscreen mode

3. Символические константы(Symbolic Constants), то есть неизменяемые переменные(Immutable Variables) и модификатор(Modifier) const; а также директива препроцессора с подстановкой во время компиляции(Compile-time Substitution) #define.

#define PI 3.14159 //symbollic constant
const double g = 9.81; //also symbollic constant
double rad = 180 / PI; //this line after preprocessing turns into the next line
double rad = 180 / 3.14159; //this line with substitution is then compiled
Enter fullscreen mode Exit fullscreen mode

4. Зависящие от реализации(Implementation-dependent) типы с описывающими их символическими константами в limits.h: ULLONG_MAX, CHAR_BIT, USHRT_MIN, SCHAR_MIN; и float.h: FLT_EPSILON, FLT_MANT_DIG, DBL_DIG.

5. Возвращаемое значение(Return Value) функций printf() — количество успешно выведенных символов; и scanf() — количество успешно введённых аргументов.

int output = printf("Hello!\n");
printf("%d\n", output); //seven sucessfully printed characters
int input = scanf("%d", &input);
printf("%d", input); //either zero or one successfull input
Enter fullscreen mode Exit fullscreen mode

6. Проблема несоответствия типа преобразований(Mismatched Conversions).
Mismatched Conversions

7. Обработка ввода функцией scanf(): пробельные символы(Whitespaces) — все введённые Enter, Space и Tab; и чтение с потока ввода(Input) — временного файла откуда всё выводится на консоль.

int n1, n2, n3;
char c1, c2, c3;

//unsuccessfull input of c1, always assigned with '\n'
scanf("%d", &n1); //number entered then Enter pressed
scanf("%c", &c1); //after '\n' was assigned to c1
printf("First input: %d%c\n", n1, c1);

//successfull input only with ',' otherwise c2 is not assigned with any character
scanf("%d,%c", &n2, &c2); //after number expected ','
printf("Second input: %d,%c\n", n2, c2);

//successfull input of c3 in all cases 
scanf("%d", &n3); //number entered then Enter pressed
scanf(" %c", &c3); //all whitespaces are ignored
printf("Third input: %d %c\n", n3, c3);
Enter fullscreen mode Exit fullscreen mode

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

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Retry later