integers which can store numbers in the range [ 2^-15 - 2^16-1]
strings which can store letters only, to use strings we need to include the string.h library
char which can store only one character or numbers from [ -128 - 127 ]
For each variable we can use the switch long before them , for example longint= " long integer " which allows us to store a larger number, or the switch singed/unsiged. For example unsignedint means that we always take only the positive value. Finally the simplest operators are " + ", " - " which allow us to make calculations and later on we will learn other operators as +=, ++ etc.
Below is a programm that I wrote and I have explained every command in the comments after the " // ".
1: #include<stdio.h>
2: #include <windows.h>
3: int main ()
4: {
5: int a,b,s; //we declare 3 integer variables
6: printf("Enter Nr1:"); // we ask for the first number
7: scanf("%d",&a); // scanf command stores the value of the number we enter on the integer a
8: printf("EnterNr2:");
9: scanf("%d",&b); //store the value of number 2 on the integer b
10: s=a+b; // calculate the sum and store it on the variable b
11: printf("Sum=%d",s); // we print the sum, the %d switch tells the compiler to print a whole number
12: system("pause"); // we just freeze the program so it doesn't end automaticlly, we need to press any key for it to end
13: return 0;
14: }
Download the .c file of the program above : Download
Previous Tutorial << >> Next Tutorial will be posted on 30 March