Introduction of C language
C is a general-purpose programming language
created by Dennis Ritchie at the Bell Laboratories in 1972.
It is a very popular language, despite being old.
The main reason for its popularity is because it is a fundamental language in
the field of computer science.
C is strongly associated with UNIX, as it was
developed to write the UNIX operating system.
1.Header file:
1.Header file is a file that contains
function deceleration and macro definition for c in built library.
2.All std. library function of c are in built in c.
3.we use it like #include<stdio.h>.
Examples:
- stdio.h: Contains
functions for input and output.
- stdlib.h: Contains
general-purpose functions like memory allocation, process control, etc.
- math.h: Contains mathematical
functions.
- string.h: Contains functions for
string manipulation.
2.Variables: It
collects memory for data or assign memory for data.
(Container for storing datatype)
Syntax : data_type identifiers
(var_name ).
Examples : int a; float a; char a;
3.Types of Variables: There
are two types of variables.
1. Local Variable.
2. Global Variable.
A. Local Variables:
1.These are declared within the function and cannot
be accessed out side the function.
2.The scope (range) of local variables will
be within the function only.
Program
:
#include<stdio.h>
------------------Header file
int main ()
{
int a=10,b=20; //a,b are local variable
printf("a=%d, b=%d",a,b);
}
Output :
B. Global Variables:
1.This variables can be accessed any where from the
program.
2. Tis variables are defined outside the main
function.
3.Hence, this variable is visible to main function
and all other sub function.
Program :
#include<stdio.h> ------------------Header file
int
a=10,b=20; //a,b are Global variable
int main ()
{
printf("a=%d, b=%d",a,b);
}
Output :
4. Variables
1.It is the name given to the variables.
2.Certain words like 'int' , 'main' etc. are some
of the reserved key words and cannot be used as identifiers.
3. It contains alphabets , numbers or underscores
and we cannot use double underscores . Because they are case
sensitive.
Examples : total
, sum , average , _m_, sum_1, sum1 .
5.Keywords :
1.These words have their own meaning.
2.These keywords are associated with there own
specific featrures.
Examples : int , float , char , if , else,
etc.
6.Data types : There are two types of datatypes .
1. Primary Data Type.
2. Derived Data Type.
Primary Data Type |
Derived Data Type |
1.Integer |
1.Array |
2.Float |
2.Pointer |
3.Character |
3.Structure |
4.Double |
4.Enumeration |
A. Primary data type :
Data type |
Description |
size |
Examples |
int (%d) |
Stores whole numbers, without decimals |
2 or 4 bytes |
1 |
float (%f) |
Stores fractional numbers, containing
one or more decimals. Sufficient for storing 6-7 decimal
digits. |
4 bytes |
1.99 |
double
(%lf) |
Stores fractional numbers, containing one or
more decimals. Sufficient for storing 15 decimal digits. |
8 bytes |
1.99999 |
char (%c) |
Stores a single character/letter/number, or
ASCII values |
1 byte |
‘A’ |
B. Derived data type :
Derived Data Type |
Description |
1.Array |
It is collection similar data. |
2.Pointers |
It points to the address of
another variable. |
3.Structure |
It is a collection of
different type of data. |
The structure of a C program consists of the following sections:
Header file
preprocessor;
(semicolon means end of statement)
Global
variable Declaretion
main ()
{
Local Statement
Block of Statement
}
0 Comments