In the previous tutorial we are discuses about c compiler
and write a simple print program if you don’t read the tutorial then go to thislink and read the first tutorial.
Today we discusses about header file of c language and data
type of c and write some program.
Header files:
- · stdio.h: for standardized input and output function.
- · conio.h: for clearing the screen.
- · string.h: for string handling function.
- · stdlib.h: for some miscellaneous.
- · math.h: for mathematical function.
- · alloc.h: for dynamic memory allocation.
Header files are system define function.
All the header files are referenced at the start of the
source code file that uses one or more function from that file.
Header files are add by the flowing #include or
#include
You can’t understand the all header files works now but when
we will write the program then you can easily understand where we include the
proper header file.
In first tutorial we used stdio.h header file it is use to
read keyboard input and output function.
Basic data type in c:
C language provides very few basic data types like
Character, integer, floating point, double valueless.
Table list of data types:
Data Type
|
Keyword used
|
Size in Bytes
|
Range
|
Use
|
Character
|
char
|
1
|
-128 to +127
|
To store characters
|
Integer
|
int
|
2
|
-32768 to
+32767
|
To store
integer numbers
|
Floating Point
|
float
|
4
|
3.4E-38 to304E+38
|
To store floating point numbers
|
Double
|
double
|
8
|
1.7E-308
to 1.7E+308
|
To store
big floating point numbers
|
Valueless
|
void
|
0
|
Valueless
|
--
|
See the table carefully and try to remember it.
Now we are write a program that display us a integer number.
#include
int main ()
{
int num;
num = 12;
printf("The
number is %d", num);
return 0;
}
Output: The number is 12.
int num; its means here is a integer variable named num it’s
called variable declare.
Next line we declared num = 12. So the integer number is 12.
printf function display us the number 12, %d used to display
integer number.
printf(“The number is %d”, num); hear %d is replaced by the value of num.
So the output is The number is 12.
So the output is The number is 12.
Now we write another program that read input from the user
and display it.
#include
int main ()
{
int num;
printf("Enter
any number :");
scanf("%d", &num);
printf("The
number is %d", num);
return 0;
}
Output :
Enter any number 12
The number is 12
It is same as the previous program just add two extra line.
You can see here we use a new function scanf it is used to
read the keyboard intup.
%d is defined that the input must be integer number and
&num the address of the integer value where the value is store.
Other code are the same as the previous program.
In the previous program we initialised the value of num in program time and in this
program the valu of num initialised in run time.
Ok that’s enough for the second day now practise this programs
and modify the programs and run.
If any error in the programs feel free to comment bellow. Thanks
0 comments Blogger 0 Facebook
Post a Comment