Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 138 - CoreGPT(Podar)_Flipbook_C8
P. 138

    Data Type             Size (in bytes)                          Range
                                                                        -1.7976931348623157 × 10³⁰⁸ to
                       double                               8
                                                                        1.7976931348623157 × 10³⁰⁸
                                                                        ~ -1.189731495357231765 × 10⁴⁹³² to ~
                       long double                         12
                                                                        1.189731495357231765 × 10⁴⁹³²

                      Non-Primitive Data Types

                      Non-primitive data types are user-defined data types in C++ that are used to store multiple
                      values  or  create  custom  data  structures.  The  table  below  shows  the  types,  descriptions  and
                      examples of common non-primitive data types in C++:

                         Data Type                              Description                                Example
                                                                                                        class Student {
                                       A user-defined type that can hold both data and functions;
                       class                                                                            int rollNo;
                                       used in object-oriented programming.
                                                                                                        };
                                                                                                        struct Book {
                                       A  lightweight  user-defined  type  to  group  different  data  string title; int
                       struct
                                       types together.                                                  pages;
                                                                                                         };
                                                                                                        enum Day {
                                       A user-defined type that assigns names to a set of integer
                       enum                                                                             SUN, MON, TUE
                                       constants.
                                                                                                        };
                                                                                                        union Data {
                                       A  user-defined  type  where  all  members  share  the  same
                       union                                                                            int x; float y;
                                       memory location; only one value can be stored at a time.
                                                                                                        };
                      Variables

                      Variables are memory locations used to store values. When a variable is created, a specific size
                      of memory space is allocated for it. This space is referred to by the name assigned to the variable,
                      which is called an identifier.
                      Naming Conventions for Variables

                      Following are the naming conventions used to declare a variable in C++:
                          A variable name must start with a letter (a–z, A–Z) or an underscore ( _ ).

                          A variable name cannot start with a digit (0-9).
                          Keywords cannot be used as variable names.
                          A variable can only contain alpha-numeric characters and underscore (A–Z both capital as

                          well as small) and (0–9) numbers.
                          No special symbols like ! , @ , #, $, %, etc. can be used in variable name.
                          Variable names are case sensitive, meaning myVar and MyVar are different.

                          Variable names cannot contain blank space.

                    136     Premium Edition-VIII

| 133 134 135 136 137 138 139 140 141 142 143 |