英語版 Introduction to C Language that Takes You to Heaven: Hexadecimal Structures ver. 2.2117
Welcome to the Introduction to C Programming that can take you to Heaven: Hexadecimal Structures
Welcome to the Introduction to C Programming that can take you to Heaven: Hexadecimal Structures
Welcome to the Introduction to C Programming that can take you to Heaven: Hexadecimal Structures
Welcome to Introduction to C Programming That Can Take You to Heaven: Hexadecimal Structures. My name is Aresa, and I'll be your guide.
Nice to meet you.
This book is a sequel to Season 1 of Introduction to C Programming That Can Take You to Heaven. In Season 1, you can learn the basics of C programming, such as how to write programs, how to compile them, how to use the printf function, how variables work, the properties of binary numbers, and how data is stored in memory.
You can access Season 1 at this address:
👇https://kakuyomu.jp/works/1177354054881541562
In Introduction to C Programming That Can Take You to Heaven: Hexadecimal Structures, we explain the basics of C programming, such as how to use if statements, for loops, arrays, pointer variables, how to create files on your hard disk and store data, and the structure of structures, in the form of a conversation.
You can read the book from the first episode, or click the ≔ symbol in the upper right corner of the book to access the table of contents at this address:
👇
https://kakuyomu.jp/works/1177354054881541503. From there, you can select the section you need and read it.
Also, you can access the table of contents for Introduction to C++ Programming That Can Take You to Heaven at this address:
👇
https://kakuyomu.jp/works/1177354054884384072.
To make this book easy to read,
click on the ≔ mark at the top right of the book and choose your preferred settings from the viewer settings, such as the font size and whether to display in Ming or Gothic font.
"Heavenly C Language Introduction: Hexahedral Structure" is a C language reference book that extends towards heaven like a plant that grows two leaves, and the two leaves grow into young leaves while cooperating and exchanging information with "Heavenly C Language Introduction" to support each other's growth in a relationship like that of hexahedral structures. Therefore, this book is not an attachment to "Heavenly C Language Introduction," but an equal relationship where they support each other's growth.
The text generates articles randomly, so there are many ??? or Wah Wah ??? parts (laughs), but since it is in hexahedral structure, it eventually becomes a mechanism that can be understood. I would like to talk about hexahedral structures in another episode.
If you read it together with "Heavenly C Language Introduction," your understanding will improve significantly.
All the source code in the main text can be copied and pasted, and you can paste it into your editor and run it. I hope it will be helpful for your learning.
Consideration of the char variable type
A char type variable is used to store character data (one-byte alphanumeric characters).
Let's try to store the character ☆a☆ in a char type variable.
In this case, we surround☆a☆with single quotes, and then we assign the result 'a' to the char type variable "character." If we don't do this, 'a' will not be recognized as character data by the compiler. If we write 'a' as is in the source code, a compile error will occur.
Similarly, if we surround the number 1 with single quotes and write '1'
it will be recognized as character data '1' by the compiler, not as a numerical data 1.
What is the difference between numerical data 1 and character data '1'?
The data stored in memory is different.
If we store numerical data 1 in a char type variable, the memory will store 00000001 (8 bits).
If we store character data '1' in a char type variable, the memory will store 00110001 (8 bits).
When you execute the following program below,
👇
#include <stdio.h>
int main()
{
char character;
character = 'a';
printf("%c\n", character);
return 0;
}
The program output will be
a
When you declare a char type variable with the following code:
char character;
Although the variable name "character" can use up to 9 characters, the char type variable can only store a single character. This limitation makes it interesting.
The %c output conversion specifier is used for either
🌞a character data or a variable that stores character data.🌞
It is used to output a single character (half-width alphanumeric character) to the command prompt screen with printf.
The %c output conversion specifier is an essential tool for displaying a single character (half-width alphanumeric character) on the command prompt screen.
On the other hand, with the %d output conversion specifier, you can only output an integer value to the command prompt screen and not a character.
If we do not declare a variable of char type, but directly use only the character data 'a' as the second argument of the printf function, let's display
a
on the command prompt screen using printf.
Please see the following program:
👇
#include <stdio.h>
int main(void)
{
printf("%c\n", 'a');
return 0;
}
The output result of the program is
a
If we don't store the data information of the character data 'a' somewhere in the computer's memory, we cannot display it with printf.
This means that the character data 'a' is automatically stored somewhere in the memory in the char type format, even if we do not declare a variable of char type and assign it with
character = 'a'.
This is because the other variable types int, float, and double are designed to only store numerical data.
(Note: the idea is good, but it is not actually accurate. Please see the postscript at the end of the text.)
=====================================
Here, without any context (^_^), the topic suddenly changes
in "Introduction to C Programming to Get to Heaven - Hexa-structure."
In the world of Hexa-structure, there is no concept of proceeding in order.💖💖💖
=====================================
Please translate the following passage:
If you try to use %d instead of %c and print 'a' with the printf function, the result will be:
#include <stdio.h>
int main()
{
perl
Copy code
printf("%d\n", 'a');
return 0;
}
The output of this program is 97.
It's strange, isn't it?
%d output conversion specifier treats the character 'a' as a number and returns its ASCII code, which is 97.
To make the compiler recognize a character
b
c
・
・
・
as a character, we need to enclose it in single quotes, like this:
'b' 98
'c' 99
'd' 100
'e' 101
'f' 102
'g' 103
'h' 104
'i' 105
'j' 106
'k' 107
'l' 108
'm' 109
'n' 110
'o' 111
'p' 112
'q' 113
'r' 114
's' 115
't' 116
'u' 117
'v' 118
'w' 119
'x' 120
'y' 121
'z' 122
If we use %d to output the corresponding integer values of these characters, we get their ASCII codes. For example, 'b' has an ASCII code of 98, 'c' has an ASCII code of 99, and so on.
These ASCII codes are assigned to each character, and we can use them to display characters on the command prompt using printf.
The following program is an example of how to use ASCII codes to print characters on the command prompt:
#include <stdio.h>
int main()
{
printf("%c\n", 97);
return 0;
}
The output of the program:
a
Using ASCII code 97, we were able to display "a" on the command prompt.
To display a character corresponding to an ASCII code using printf, the %c conversion specifier is used.
If we were to use the %d conversion specifier to display an integer value, like in the following program:
#include <stdio.h>
int main()
{
printf("%d\n", 97);
return 0;
}
The output of the program would simply be:
97
Yes, that's correct.
What's that? 8 bits make up one octet...
I understand.
In reality, when a one-byte data representing a character data like 'a' is passed as an argument to printf() function as shown in the example below,
printf("%c\n", 'a');
it is passed as a four-byte (int type) data representing an integer value to the printf() function.
To be specific, a numerical value of 97 is assigned to the character data 'a'.
In other words, the value 01100001 is assigned as a numerical value to the character data 'a' in binary format.
However, when character data 'a' is passed as an argument to the printf() function, it is converted into an integer value of int type (which is 4 bytes) due to data processing limitations.
Therefore, the value 01100001 (1-byte numerical data stored in char type) is converted to 00000000000000000000000001100001 (4-byte numerical data stored in int type) and passed as an argument to printf() function.
新規登録で充実の読書を
- マイページ
- 読書の状況から作品を自動で分類して簡単に管理できる
- 小説の未読話数がひと目でわかり前回の続きから読める
- フォローしたユーザーの活動を追える
- 通知
- 小説の更新や作者の新作の情報を受け取れる
- 閲覧履歴
- 以前読んだ小説が一覧で見つけやすい
アカウントをお持ちの方はログイン
ビューワー設定
文字サイズ
背景色
フォント
組み方向
機能をオンにすると、画面の下部をタップする度に自動的にスクロールして読み進められます。
応援すると応援コメントも書けます