c++ to find size of char
#include <iostream>
int main() {
char c;
std::cout << "Size of char: " << sizeof(c) << " bytes" << std::endl;
return 0;
}
Explanation:
#include <iostream>
: Includes the input/output stream library, allowing for input and output operations.int main() { ... }
: Defines the main function where the program execution begins.char c;
: Declares a variablec
of typechar
.std::cout << "Size of char: " << sizeof(c) << " bytes" << std::endl;
: Prints the size of thechar
variablec
usingsizeof()
function. Thesizeof()
function returns the size in bytes of its argument. The output is displayed usingstd::cout
followed bystd::endl
to end the line.return 0;
: Indicates successful completion of themain()
function.