Skip to content

Maharth1906/Data-Types-CPP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Aim: To study and implement C++ Program Structure (Data Types)

Apparatus: GNU g++ compiler for local and code editor.

Program Explanation: The program begins from #include for input/output operations and then #include to demonstrate the string data type. The using namespace std; statement allows the use of cout, cin, string, etc. without using std:: beforehand.

Program Flow In the main() function, the program illustrates the declaration, input, and size of various C++ data types:

Integer (int): The user is prompted for an integer, which is printed along with its size in bytes using sizeof() which is of 4 bytes.

Floating-point (float): The program accepts a float input (decimal number) and prints the value and its size in memory which is of 4 bytes.

Character (char): The program reads a single character from user input, then prints it and its size which is of 1 bytes.

Double (double): The user is prompted to input a double-precision floating-point number, which is then printed with its size which is of 8 bytes.

String (string): The program accepts a word (the program notes that cin will read input until the first space), prints the string, and its size in memory. The program uses sizeof(string), which returns the fixed size of the string object itself, not the length of the string which is of 24 bytes.

Boolean (bool): The program accepts a boolean input(0= false, 1=true), shows it, then prints the size which is of 1 bytes.

Key Concept: sizeof() Operator: It finds out how much memory (in bytes) each data type occupies. Data Representation: This program illustrates how different data types represent various data and the memory requirement of each. User Interaction: For every data type, the program asks the user, reads the input with cin, then outputs the value and the size of the datatype.

Conclusion: The program ends after showing all the values and their memory sizes. This helps users learn how to practically use datatypes in C++, but it also introduces the idea of memory allocation for datatypes. This is essential in understanding data storage and management in programming.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages