Check The Programming Section
The first program we did, “Hello, World!” it simply puts the message into the computer screen what we have provided. In the real world programming environment, we normally take input from the user and process them to give one or more expected output. To take input, we need somewhere to store that value into computer memory. Later on these values are read back from the same memory location, where they are stored. Those memory blocks have two attributes:
A name, using this name, we read back this data and this name represents the memory block
A type name, which informes the compiler about what type of data that memory block can hold.
We will talk about this name a little bit later, now let us first understand why a type name is required?
In our daily life activities, we came across with various types of data such as
Name of a place where we are live
Pincode of the area
While filling a web form, suppose an email account, we needs to provide our age
Sometimes we also needs to put information about our gender as M for Male and so on
When we purchase some item from a supermarket, and process out billing information, we have an exact amount and it is found that the product rate may have a fractional part like ₹45.67.
So, in C/C++, to input these values we need to allocate a memory block first. This memory block will be used for taking input of any of these values and how much memory size in byte/s its required to reserve, it is decided by the type name. Let us understand the inportnat of type name with few examples:
Age of a person in years may varies in between 0 (zero) to 100
Name of person or name of a city where we work, is a combination of characters such New Delhi
At present a mobile number consits of 10 digits a decimal number such as 9999900230 (belongs to no one, just for example purpose)
Based on the type of value C/C++ have 5 (five) atomic data type and based on these type a memory block with fixed-size is allocated to a name.
Abbreviations listed in the above Table are reserved keywords and their meaning is defined in C/C++ compiler. The minimum size required to store information is 1 byte (equal to 8 bits).
To allocate one byte memory block to store any information with a single character the abbreviation char will be used. The required syantx is
char gender = 'M';
The type of gender is char and can store maximum one characters and single quotes are used.
The minimum memory requirement is 2 bytes for 16 bits system and 4 bytes for 32 bits system. To store any decimal value the keyword int is used and the required syntax is
int pincode = 110001;
To store any value with 6th decimal place, we needs to reserve memory of 4 bytes and for that float keyword is used
float balance = 45.0945;
To store any fractional value which requires upto 10th decimal place we needs to reserve a memory bolck of 8 bytes with keyword double
double latitude = 35.6789034;
These names gender, pincode, balance and latitude are called indentifies in C/C++ and there are some specific rules already defined about this. About the type of identifier name we will discussed in variables and constant section of this tutorial.
The type void is used for two purpose only. Such as
returning type of a function, which returns no value to the calling function and
used to create generic pointers.
Both of these uses are discussed in subsequent chapters. Further thses basic types are combined and two other data types are formed. Such as
Derived data type
User-defined data types
Further basic data types are used to form various data types. Such as
array
function
pointer
reference (in C++)
We will talk about them, when there is a requirement of any of these data type. Out of these, let us discuss the character array to store a name into computer memory.
During discussion of basic data types, we have picked an example as the name of a place where we live or work represented as a sequence of characters. The derived data type array is used to represent such information into memory. A name is a collection of characters and we know that a character data type can store one character only. To store a name into memory consider the following character array declaration:
char name[20] = "Sunil Kumar";
The name is a character array and also called a string in C/C++. During the discussion of "Hello, World!" program we have discussed that a string is represented using a double quote " ". Similarly, we have used double quotes to assign a value "Sunil Kumar" to character array name. In the square bracket [ ] the decimal value 20 specifies the size of the memory block in bytes allocated to name.
C supports four (4) user-defined data types those are designed by combining the basic and derived data type and the memory requirement is not fixed like basic data type. These are as follows:
structure
union
enumeration
typedef
class (in C++)
These user-defined types are used store the information like an entity such as Animal, Student, Employee and so on. We will discuss about these types as the last part of these tutorial and class will be introduced, while we start Object Oriented Programming as the second part of this tutorial.