Introduction: Integers in C++ and Some Basic Programs
We all know what are integers but what are integers in c++ and their different data types.Also we will practice some of he basic programs.....GOOD LUCK
Step 1: WHAT ARE DATA TYPES
In computer programming, information is stored in a computer memory with different data types. We must know what is to be stored in a computer memory,whether it is a simple number, a letter or a very large number. As we also know, computer memory is organized in bytes, and for these variables with varying information a data type is associated. The minimum amount of memory in computer memory is a byte, that can store a small amount of data and managed easily. Every variable is declared with two entities, its type and its name. There are several data types available in C++. The basic built in data types are char, int, float, double and bool. There is another data type void, which we will discuss some other time. C++ also allows user defined data types.
YOU CAN REFER TO THE IMAGE ABOVE FOR A WELL DEFINED TABLE OF DATA TYPES....
Step 2: DECLARING INTEGERS
To Declare any variable in C++ you need to follow rules and regulation of C++ Language, which is given below;
1) Every variable name should start with alphabets or underscore (_).
2) No spaces are allowed in variable declaration.
3) Except underscore (_) no special symbol are allowed in the middle of the variable declaration.
4) Maximum length of variable is 8 characters depend on compiler and operation system.5)Every variable name always should exist in the left hand side of assignment operator.
5) No keyword should access variable name.
Example: int a;
Step 3: Storing Values in Integer or Getting Input From the User
1) If you want to store values in integer following is the syntax for it:
int a = 5;
Remember to put a semi colon (;) after the end of every line of syntax because it tells the compiler that the line ends at this point.
2) If you want to get an input from the user for a number then following is the syntax:
int a; // declaration of an integer
cin >> a; // cin is the function that tells the compiler to get input from the user , then the two triangle brackets and then the variable name in which you want to store the value......
Step 4: How to Perform Mathematical Operations Using Operators
If u want to perform mathematical operations following are some basic operators:
1) Add - (+)
2) Subtract - (-)
3) Multiply - (*)
4) Divide - (/)
int a=5 , b=6;
int c = a * b; or int c = a + b; or int c = a - b; or int c = a / b;
Step 5: Some Basic Programs
1) declare an integer a and store a value in it and print it on the screen.
2) declare an integer a and input its value from the user and print it on the screen.
3) declare 2 integers store a value in them and store the value of their sum and print on the screen
4) declare 2 integers input their value from the user and store the value of their sum and print on the screen
try solving these programs and submit any queries in the comments...........
MY NEXT INSTRUCTABLE WOULD BE ON MORE ABOUT OPERATORS
PLEASE VISIT MY HELLO WORLD PROGRAM PAGE TOO: hello world program for c++
TAKE A LOOK AT MY NEXT INSTRUCTABLE: operators in c++