Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Unit 2 Basics of C++ and Conditional Statements Part A: Basics of C++ Basic Data Types: All variables use data type during declaration to restrict the type of data to be stored. Therefore, we can say that data types are used to tell the variables the type of data they can store. Whenever a va...

Unit 2 Basics of C++ and Conditional Statements Part A: Basics of C++ Basic Data Types: All variables use data type during declaration to restrict the type of data to be stored. Therefore, we can say that data types are used to tell the variables the type of data they can store. Whenever a variable is defined in C++, the compiler allocates some memory for that variable based on the data type with which it is declared. Every data type requires a different amount of memory. Data types specify the size and types of values to be stored. C++ supports the following data types: 1. Primary or Built-in or Fundamental data type 2. Derived data types 3. User-defined data types Primitive Data Types: 1. Integer: The keyword used for integer data types is int. Integers typically require 4 bytes of memory space and range from -2147483648 to 2147483647. For example, int salary = 85000; 2. Floating Point: Floating Point data type is used for storing single-precision floating-point values or decimal values. The keyword used for the floating-point data type is float. Float variables typically require 4 bytes of memory space. For example, float area = 64.74; 3. Double Floating Point: Double Floating Point data type is used for storing double-precision floating-point values or decimal values. The keyword used for the double floating-point data type is double. Double variables typically require 8 bytes of memory space. For example, double volume = 134.64534; 4. Character: Character data type is used for storing characters. The keyword used for the character data type is char. Characters typically require 1 byte of memory space and range from -128 to 127 or 0 to 255. For example, char test = 'h'; 5. Boolean: Boolean data type is used for storing Boolean or logical values. A Boolean variable can store either true or false. The keyword used for the Boolean data type is bool. For example, bool cond = false; 6. void: Void means without any value. void data type represents a valueless entity. A void data type is used for those function which does not return a value. Note: We cannot declare variables of the void type. 7. Wide Character: Wide character data type is also a character data type but this data type has a size greater than the normal 8-bit data type. Represented by wchar_t. It is generally 2 or 4 bytes long. For example, wchar_t i = L'b'; 8. sizeof() operator: sizeof() operator is used to find the number of bytes occupied by a variable/data type in computer memory. For example, cout = greater than or equal to the a>=b; or Equal To second operand // returns false int a = 3, b = 6; Checks if first operand is lesser Less Than < a

Use Quizgecko on...
Browser
Browser