Welcome Programmers,


In order to excel in any field the very first thing that should be very clear in one's mind is the basics and fundamentals. As we have already done/kickstarted our learning with "Hello World " program in four languages such as C, C++, Java, Python and now its time to to start with and clear our basic concepts so that we don't make any minor errors in future due to lack of knowledge.
In this post we will be going to learn about the keywords, variables and datatypes.

Topics to be covered:-
--> What are keywords ?
--> Number of keywords in C, C++, Java, Python.
--> What are Variables ?
--> What is the use of variables ?
--> How to declare Variables in C, C++, Java, Python.
--> What is Datatype ?
--> Type of Datatypes and their Size.
--> Use of Datatypes in C, C++, Java, Python.
--> Example Syntax in C, C++, Java, Python.

What are keywords ?

Keyword is a word we use in any programming language which has a specific meaning and perform a particular task. In any Programming Language the definition and meaning of the keyword is same. Keywords can not be used as a variable. Keywords are pre-defined identifiers that are already in built in the programming language. Keywords are Case-sensitive.

Example:- 
1. printf, scanf etc. are the keywords of C language.
2. cout, cin, clrscr etc. are the keywords of C++ language.
3. print, input etc. are the keywords of Python Language.
4. println, print, System case and many more are the keywords of Java language.

It is also to be noted that there may be a keyword that is same/used in many languages. example: let's say a keyword 'break' it is used in C, C++, Java, Python too. Take another keyword 'clrscr' it is used in both C as well as C++.

Number of keywords in C++, Java, Python.
In this segment we will just give a knowledge about the number of keyword in different languages, so that you are updated and informative about your specific programming language.

1) In C language we have 32 Keywords.
2) In C++ language we have 95 Keywords.(as per C++ 11)
3) In Java language we have 52 keywords.
4) In Python language we have 35 Keywords. (This number is as per python 3.7.5 it may vary in further versions)

What are Variables ?

Variable is like a container to store a value of a particular type in a memory location. It is like a identifier in program where the data is labeled and then given to the computer for processing. It can also be said as a medium through which computer gets the information for processing.

There are some predefined rules for variables:
1. Variables should not start with capital letter.
2. Variables should not start with numbers or special characters.
3. Variables should not be repeated.
4. Variables should not be the same as function name.(optional)

What is the use of variables ?

The basic use of variable is to store the information or set of information.
But apart from this it also have some different uses like: it is used to take the input from the user, Many operations can be performed on the variable.

# Syntax of declaring a variable in different languages:-


C/C++ : "datatype <space> variable name;"
int a;

Python : "variable name = its value"
a = 10

Java : "datatype <space> variable name;"
         int a = 50;

In C/C++ variable value can be assigned either on the line of declaration or after declaration.

In Python variable value has to be assigned at the time of declaration, the reason is in python we don't write the datatype for the variable at the time of declaration, if we do so it will give a "Syntax Error". Also in python the value of variable is always of string type(it is by default) in order to change its type we can use datatypes as per the requirement.

What is Datatype ?

It is used to store the data in a particular type. It can also be said that the variable is meaningless without datatype, without datatype there is no use to declare a variable. Datatypes are one of the important factors in the programming language, without Datatype the program may lose some meaning.

Type of Datatypes and their Size.

Data-types in C/C++


Sr. No. Data Type Specification/Characteristics Range
1. int It is the most used data-type for numbers in any programming language. It takes 32-bit OR 4-bytes memory. -2147483648 to 2147483647
2. long If the int data-type is not enough then we can use long data-type. It takes 64-bit OR 8-bytes memory. -9223372036854776000 to 9223372036854775999
3. __int128_t It is the largest data-type in C/C++ language. It is available in gcc compiler version 4.6 and later only. It takes 128-bit OR 16-bytes memory. -170141183460469231731687303715884105729 to 170141183460469231731687303715884105728
4. float It is the most used data-type for decimal point numbers in any programming language. It takes 32-bit OR 4-bytes memory. -157108198082446589952 to 157108198082446589951
5. double If the type float is not enough for decimal point numbers the we can use double data-type. It takes 64-bit OR 8-bytes memory. -7735413050995762138185728 to 7735413050995762138185727
6. long double It is one of the least used data-type. But the accuracy of long double data-type is more than long type. It takes 96-bit OR 12-bytes memory. -3.4 x 10^4932 to 3.4 x 10^4932
7. char It is a data-type used to store a single character data or string of single byte or letters. It takes 8-bit OR 1-byte memory. -128 to 127
8. void It is a data-type used when a function returns nothing or no-value The value of void is zero.
9. bool It is used to store a value when either its 1(True) or 0(False). It takes 8-bit OR 1-byte memory. True or False
10. short It is used to store short integer values. It takes 16-bit OR 2-bytes memory. -32768 to 32767


Data-types in Python




Sr. No. Data Type Specification/Characteristics Size
1. int This is known as an Integer type of data-type. It stores the numerical values. The size of integer varies, it depends on the value assigned to the variable. 128-bit OR 16-bytes on 32-bit system and 192-bit OR 24-bytes in 64-bit system.
2. float It is a Decimal type data-type. It is used when there is need of decimal numbers or decimal point in Python. 128-bit OR 16-bytes on 32-bit system and 192-bit OR 24-bytes in 64-bit system.
3. complex This data-type is used when a function returns a complex number constructed from the arguments. 192-bit OR 24-bytes
4. list It is used to store multiple items in a single variable. A list is mutable in nature i.e it is changeable. Lists are written using '[]' square brackets. List is stored in two blocks of memory. Creating a list is slower because two memory blocks need to be accessed. An empty list takes 36-bytes OR 288-bits, but each additional int adds 4-bytes on 32-bit system. An empty list takes 72-bytes OR 576-bits, but each additional int adds 8-bytes on 64-bit system. But for a list of long string it takes 40-bytes OR 320-bits on 32-bit system and for 64-bit system it takes 80-bytes i.e 640-bits.
5. tuple Tuples are also used to store multiple items in a single variable. They are ordered and unchangeable. They are written in round '()' round brackets. Tuple is stored in a single block of memory. Creating a tuple is faster than creating a list. An empty tuple takes 28-bytes OR 224-bits, but each additional int adds 4-bytes on 32-bit system. An empty tuple takes 56-bytes OR 448-bits, but each additional int adds 8-bytes on 64-bit system.
6. range The range data-type represents the immutable sequence of numbers and is commonly used for loops. Range sets a initial and end point so that the value won't exceed the range. -
7. dict Dictionary are used to store data values in key and value pair. It is unordered and mutable in nature. It is written in '{}' curly brackets and inside the brackets the key and value pair is written. The key and value is written in " " double inverted commas and separated by ':' colon. It takes 136-bytes OR 1088-bits for 32-bit system. For 64-bit system it takes 280-bytes OR 2240-bits.
8. str It is known as string type of data-type. It is similar to 'char' type in C/C++, here in Python it stores letters or a complete sentence. An empty string takes 25-bytes OR 200-bits, but each additional string adds 1-byte on 32-bit system. An empty string takes 37-bytes OR 296-bits, but each additional string adds 1-byte on 64-bit system.
9. bool It is used to store a value when either its 1(True) or 0(False) 8-bit OR 1-byte
10. set Sets are also used to store multiple items in a single variable. Sets are unindexable and mutable in nature. They are written in '{}' curly brackets. A set takes 116-bytes OR 928-bits on 32-bit system. For 64-bit system it takes 232-bytes OR 1856-bits
11. frozenset As we have read above that the set are mutable, the immutable version of sets are known as frozen set. The elements in the frozen set will remain the same after creation. A frozenset takes 116-bytes OR 928-bits on 32-bit system. For 64-bit system it takes 232-bytes OR 1856-bits
12. bytes Byte data-type is immutable sequence of small integers, when this data-type is used it returns a 'byte' object, which is similar to the original object. It ranges from 0 to 256. 8-bit OR 1-byte
13. bytearray Bytearray data-type is mutable sequence of integers. it returns a ew array of bytes in which every element's memory is 1-byte or 8-bit. It also ranges from 0 to 256. 8-bit OR 1-byte
14. memoryview Memory-view objects allow python code to access the internal data of an object that supports the buffer protocol without copying. Buffer protocol allows us to access the internal data of system. -


Data-types in Java

Sr. No. Data Type Specification/Characteristics Range Size
1. int It is the most used data-type for numbers in any programming language. It is a two's complement integer. -2147483648 to 2147483647 32-bit OR 4-bytes
2. long If the int data-type is not enough then we can use long data-type -9223372036854776000 to 9223372036854775999 64-bit OR 8-bytes
3. byte It is a two's complement integer. -128 to 127 8-bit OR 1-bytes
4. float It is the most used data-type for decimal point numbers in any programming language. -157108198082446589952 to 157108198082446589951 32-bit OR 4-bytes
5. double If the type float is not enough for decimal point numbers the we can use double data-type -7735413050995762138185728 to 7735413050995762138185727 64-bit OR 8-bytes
6. char It is a data-type used to store a single character data or string of single byte or letters. -128 to 127 8-bit OR 1-byte
7. boolean It is used to store a value when either its 1(True) or 0(False) True or False 8-bit OR 1-byte
8. short It is used to store short integer values. It is a two's complement integer. -32768 to 32767 16-bit OR 2-bytes



Use of Datatypes in C, C++, Java, Python.


C/C++:-
In C/C++ the use of data type is same.
In both the languages it is used to define the type of data. When taking the values from the user, datatype given to the variable decides what type of value should be entered.
It is also used for declaration of variable.
It is also defines the size of the variable

Python:-
In Python the datatype is used for converting an input data or already mentioned data in program from one type to another type.
In python unlike other languages like C,C++,Java datatypes are not used for declaring variable.
It is also defines the size of the variable

Java:-
In java datatype is used before variable in order to determine the type of data that is to be stored in the variable.
In other way we can also say that datatypes gives variation to the variable for containing data.
It is also defines the size of the variable

Example Syntax in C, C++, Java, Python.

Syntax for datatypes and variable in C:
 int b; 
here 'int' is a datatype and 'b' is a variable name.


Syntax for datatypes and variable in C++:
int b; 
Here 'int' is a datatype and 'b' is a variable name.


Syntax for datatypes and variable in Python:
 b = 20 
 print(int(20))
 
Here in the first line variable is 'b' and '20' is its value, and in the second line 'int' is the datatype used to convert the 'string' type to 'int' type.

Note: In python the input and all the variable is by default set to string type. Its changed only when you give it a datatype.


Syntax for datatypes and variables in Java:
int b = 23; 
Here 'int' is the datatype and 'b' is the variable name and '23' is the value. The same way can also be done for C and C++ languages.


So in this post we have tried to focus on some basic concepts from next post we will explore more the world of programming. Till there stay tuned.

#ENJOY CODING#

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post