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 variable c of type char.

  • std::cout << "Size of char: " << sizeof(c) << " bytes" << std::endl;: Prints the size of the char variable c using sizeof() function. The sizeof() function returns the size in bytes of its argument. The output is displayed using std::cout followed by std::endl to end the line.

  • return 0;: Indicates successful completion of the main() function.