C ++ type bool (bool)

Six, C ++ type bool (bool)

1, BOOL type in C ++ basic data types, specifically represent logical value;
2, BOOL of one byte in memory, represents a logical true, a logical 0 indicates false;
. 3, BOOL variable can accept any type of expression As a result, compared with a non-zero value true (1), a value of 0 was false (0).

bool.cpp

#include <iostream>
using namespace std;

int main(void){
	bool b = false;
	cout << "size=" << sizeof(b) << endl;//1
	cout << b << endl;//0

	b = 123;
	cout << b << endl;//1
	b = 3.14;
	cout << b << endl;//1
	char* p = NULL;//NULL-->(void *)0
	b = p;
	cout << b << endl;//0
	return 0;
}
Released seven original articles · won praise 0 · Views 157

Guess you like

Origin blog.csdn.net/weixin_42284219/article/details/104544619