Home > Backend Development > C#.Net Tutorial > Is true and false in C language 1 and 0?

Is true and false in C language 1 and 0?

烟雨青岚
Release: 2020-07-15 11:35:01
Original
23277 people have browsed it

C language true and false are "1" and "0". In C language, "0" is false, "1" is true, and the logical AND is the same as integer multiplication; "1" in C language is an integer, and the result of integer division "1/2" will also be an integer. The answer in mathematics is " 0.5", but the integer cannot save "0.5"; therefore it will directly become "0".

Is true and false in C language 1 and 0?

C language stipulates that 1 is true (TRUE) and 0 is false (FALSE).

In C language, 0 is false, 1 is true, logical AND is the same as integer multiplication, and 1 in C language is an integer, and the result of integer division 1/2 will also be an integer. The answer in mathematics It is 0.5, but integers cannot store 0,5. Therefore it will directly become 0. It doesn't matter what the subsequent calculation results are.

In general, the smallest storage unit of a computer is a byte. One byte can store 256 numbers, but there are only two numbers, true and false. The C language only has the Boolean type _ Bool since C99.

Before C99, integer types were used to store Boolean values. In addition to the two values ​​​​of true and false, there are at least 254 numbers. These numbers cannot be neither true nor false, so only one value can be used to represent true or false. , other values ​​represent the opposite of the previous value.

Is true and false in C language 1 and 0?

Extended information

The principle of computer recognition of 0 and 1

The RAM in the computer stores the program being used And files, the hard drive is where files are permanently stored. The hard disk is actually composed of several disks, which are completed by a large number of ordered magnetic particles. Magnetism can represent 0 and 1. When a file needs to be read or written, an electrical pulse signal is actually sent to move the read-write head to change the magnetism of the magnetic particles or to obtain the magnetism of the magnetic particles.

In computers, a string of numbers that are processed or calculated as a whole is called a computer word, or Yu for short. Words are usually divided into bytes (each byte is typically 8 bits). In memory, each cell typically stores one word, so each word is addressable. The length of a word is expressed in bits.

In computer arithmetic units and controllers, data is usually transmitted in units of words. Yu appears in different addresses and its meaning is different. For example, the word sent to the controller is an instruction, and the word sent to the arithmetic unit is a number.

The string of binary numbers that is accessed, transmitted, and processed as a whole in the computer is called a word or unit. The length of the binary digits in each word is called the word length.

Recommended tutorial: "C Language Tutorial"

The above is the detailed content of Is true and false in C language 1 and 0?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template