Keywords are the words in a language that are used for some internal process or represent some predefined actions. bool is a keyword that is used to declare a variable which can store Boolean values true or false. It is an alias of System.Boolean.
Bool Keyword occupies 1 byte (8 bits) in the memory. There are only two possible values of bool i.e. true or false.
Syntax:
bool variable_name = value;
Example:
Input: true
Output: answer: False
Size of a byte variable: 1
Input: false
Output: Type of answer: System.Boolean
answer: True
Size of a bool variable: 1
Example 1:
using System;
using System.Text;
class GFG
{
static void Main( string [] args)
{
bool answer = false ;
Console.WriteLine( "answer: " + answer);
Console.WriteLine( "Size of a bool variable: " + sizeof ( bool ));
}
}
|
Output:
answer: False
Size of a bool variable: 1
Example 2:
using System;
using System.Text;
namespace geeks {
class GFG {
static void Main( string [] args)
{
bool answer = true ;
Console.WriteLine( "Type of answer: " + answer.GetType());
Console.WriteLine( "answer: " + answer);
Console.WriteLine( "Size of a bool variable: " + sizeof ( bool ));
Console.ReadLine();
}
}
}
|
Output:
Type of answer: System.Boolean
answer: True
Size of a bool variable: 1
Last Updated :
22 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...