Popular Posts
-
Now I will show you how to retrieve the data posted from a HTML file in a JSP page. Consider an html page that prompts the user to enter his...
-
Accessing the Standard CGI Variables: To build the successful web application, you often need to know a lot about the environment in which ...
-
INTRODUCTION TO 'C': C is a programming language developed at AT & T's Bell laboratories of USA in 1972.it was designed by d...
-
SQL aliases can be used with database tables and with database table columns, depending on task you are performing. SQL column aliases are u...
-
Learning about Events (Continue) Lets program the Form_Load event. "MsgBox" is Visual Basic command that launch a message box. for...
-
Steps to follow: 1. Write Person.java as shown below in Code-11.3.a under polypackage directory. (You are welcome to do this work using eit...
-
The Command Button's KeyPress, KeyDown and KeyUp Events The events that will be mentioned in the following pages are commonly used, and ...
-
The SQL AVG aggregate function selects the average value for certain table column. Have a look at the SQL AVG syntax: SELECT AVG(Column1) FR...
-
package interfaceexercise; // Define an interface with three abstract methods. // Any class that implements this interface has to // impleme...
-
We will use the Customers table to illustrate the SQL LIKE clause usage: FirstName LastName Email DOB Phone John Smith John.Smith@yaho...
Saturday, July 19, 2008
INTRODUCTION TO C
INTRODUCTION TO 'C':
C is a programming language developed at AT & T's Bell
laboratories of USA in 1972.it was designed by dennis rechie.
where C stands:
a)problem oriented languages or high level languages:
these languages have been designed to give a better programming
efficiency.i.e,faster program development.
languages in this category are FORTRAN,BASIC,PASCAL etc.
b)machine oriented languages or low level languages:
these languages have been designed to give a better machine efficiency,i.e,faster program execution.
languages in this category are assembly language and machine language.
CONSTANTS,VARIABLES AND KEYWORDS
CONSTANTS,VARIABLES AND KEYWORDS:
CONSTANTS:
Two types of constants those are:
a)primary constants
b)secondary constants
a)In primary constants they are integer,real,character constants.
b)In secondary constants they are array,pointer,structure,union,enum etc.
VARIABLES:
a variable is a dataname that may be used to store a data value.unlike constants that
remain unchanged during the execution of a program,a variable may take different values at different times during execution.
Rules for constructing variables:
1. they must begin with a letter.some systems permit underscore as the first character.
2.ANSI standard recognizes alenght of 31 characters.however,the lenght should not be normally
more than eight characters,since only the first eight charaters are treated as significant by
many compilers.
3.uppercase and lower case are significant.that is,the variable total is not the same as total or TOTAL.
4.the variable name should not be keyword.
5.white space is not allowed.
example: int a=10;//int is a datatype,a is a variable in which '10' value is stored.
KEYWORDS:
keywords are the words whose meaning has already been explained to the compiler.
this cannot be used as variable names because if we do so we are trying to assign a new meaning to the keyword.
some of the keywords are
auto double if static
break else int struct
case enum long switch
char extern near typedef etc
CONSTANTS:
Two types of constants those are:
a)primary constants
b)secondary constants
a)In primary constants they are integer,real,character constants.
b)In secondary constants they are array,pointer,structure,union,enum etc.
VARIABLES:
a variable is a dataname that may be used to store a data value.unlike constants that
remain unchanged during the execution of a program,a variable may take different values at different times during execution.
Rules for constructing variables:
1. they must begin with a letter.some systems permit underscore as the first character.
2.ANSI standard recognizes alenght of 31 characters.however,the lenght should not be normally
more than eight characters,since only the first eight charaters are treated as significant by
many compilers.
3.uppercase and lower case are significant.that is,the variable total is not the same as total or TOTAL.
4.the variable name should not be keyword.
5.white space is not allowed.
example: int a=10;//int is a datatype,a is a variable in which '10' value is stored.
KEYWORDS:
keywords are the words whose meaning has already been explained to the compiler.
this cannot be used as variable names because if we do so we are trying to assign a new meaning to the keyword.
some of the keywords are
auto double if static
break else int struct
case enum long switch
char extern near typedef etc
DATATYPES
DATATYPES:
there are 3 types of datatypes those are:
a)primary datatypes
b)user-defined datatypes
c)derived data types
primary datatypes are: int,float,char,double etc.
user-defined datatypes are: typedef
derived datatypes are: arrays,pointers,structures,union,enum etc.
there are 3 types of datatypes those are:
a)primary datatypes
b)user-defined datatypes
c)derived data types
primary datatypes are: int,float,char,double etc.
user-defined datatypes are: typedef
derived datatypes are: arrays,pointers,structures,union,enum etc.
SYMBOLIC CONSTANTS OR MACRO
SYMBOLIC CONSTANTS OR MACRO:
In this #define is a macro used for a constant value to be assigned in the program.
for example: pi its value is being fixed as 3.14 so
we can assign:
ex: #define pi 3.14
Rules for symbolic constants:
1.symbolic names have the same form as variable names.these are written in capitals to differ from ordinary variables.
2.No blank space between the pound sign '#' and the word define is permitted.
3.'#' must be the first character in the line.
4.A blank space is required between #define and symbolic name and between the symbolic name and the constant.
5.#define statements must not end with a semicolon.
6.after definition,the symbolic name should not be assigned any other value within the program by using an assignment statement.For ex: STRENGTH=200;is illegal.
7.symbolic names are NOT declared for data types .its data types depends on the type of constant.
In this #define is a macro used for a constant value to be assigned in the program.
for example: pi its value is being fixed as 3.14 so
we can assign:
ex: #define pi 3.14
Rules for symbolic constants:
1.symbolic names have the same form as variable names.these are written in capitals to differ from ordinary variables.
2.No blank space between the pound sign '#' and the word define is permitted.
3.'#' must be the first character in the line.
4.A blank space is required between #define and symbolic name and between the symbolic name and the constant.
5.#define statements must not end with a semicolon.
6.after definition,the symbolic name should not be assigned any other value within the program by using an assignment statement.For ex: STRENGTH=200;is illegal.
7.symbolic names are NOT declared for data types .its data types depends on the type of constant.
CONTROL STRUCTURES
CONTROL STRUCTURES:
Three types of control structures:
1.Decision control structure : if,if else,nested if etc
2.Loop control structure : while loop,do..while loop, for loop,break statement,continue statement.
3.case control structure : switch,goto
1.Decision control structure:
ex: if(condition)
{
block of statements;
}
ex: if(condition)
{
block of statements;
}
else{ block of statements;}
ex: if(condition)//NESTED IF
{
if(condition1)
block of statements;
else
block statements;
}
2.Loop control structure:
ex: while(condition)
{
block statements;
}
ex: do
{
block statements;
}while(condition);
ex: for(initalization;condition;increment/decrement)//ex: for(i=0;i<=10;i++/i--)
{
block statements;
}
3.Case control structure:
ex: switch(condition)
{
case 1: statements;break;
case 2:statements;break;
default:statements;break;
}
Three types of control structures:
1.Decision control structure : if,if else,nested if etc
2.Loop control structure : while loop,do..while loop, for loop,break statement,continue statement.
3.case control structure : switch,goto
1.Decision control structure:
ex: if(condition)
{
block of statements;
}
ex: if(condition)
{
block of statements;
}
else{ block of statements;}
ex: if(condition)//NESTED IF
{
if(condition1)
block of statements;
else
block statements;
}
2.Loop control structure:
ex: while(condition)
{
block statements;
}
ex: do
{
block statements;
}while(condition);
ex: for(initalization;condition;increment/decrement)//ex: for(i=0;i<=10;i++/i--)
{
block statements;
}
3.Case control structure:
ex: switch(condition)
{
case 1: statements;break;
case 2:statements;break;
default:statements;break;
}
OPERATORS
OPERATORS:
There are 7 operators they are:
1.Arithmetic operators : +,-,*,/,% : addition,subtraction,multiply,division.
2.Relational operators : <,<=,>,>=,==,!= : lessthan,lessthan equalto,greaterthan,greaterthan equalto,is equalto,is not equalto
3.Logical operators : &&,||,! : AND,OR,NOT
4.assignment operators : +=,-=,/=,*= : example: a+=b(a=a+b)
5.Increment and Decrement operators : ++,-- : increment or decrement 1
6.Conditional operators : exp1 ? exp2:exp3 : ex: x=(a>b) ? a : b
7.Bitwise operators : &,|,^,<<,>>,~ : bitwise AND,OR,exclusive OR,shift left,shift right,one's complement.
There are 7 operators they are:
1.Arithmetic operators : +,-,*,/,% : addition,subtraction,multiply,division.
2.Relational operators : <,<=,>,>=,==,!= : lessthan,lessthan equalto,greaterthan,greaterthan equalto,is equalto,is not equalto
3.Logical operators : &&,||,! : AND,OR,NOT
4.assignment operators : +=,-=,/=,*= : example: a+=b(a=a+b)
5.Increment and Decrement operators : ++,-- : increment or decrement 1
6.Conditional operators : exp1 ? exp2:exp3 : ex: x=(a>b) ? a : b
7.Bitwise operators : &,|,^,<<,>>,~ : bitwise AND,OR,exclusive OR,shift left,shift right,one's complement.
DIFFERENCE BETWEEN STRUCT AND UNION
DIFFERENCE BETWEEN STRUCT AND UNION:
In structures,each member has its own storage location,whereas all memebers of a union use
the same location.this implies that,although a union may contain many members of different types,it can handle only one member at a time.
ex: struct book
{
char title[20];
char author[15];
int pages;
float price;
}
ex: union item
{
int m;
float x;
char c;
}code;
In structures,each member has its own storage location,whereas all memebers of a union use
the same location.this implies that,although a union may contain many members of different types,it can handle only one member at a time.
ex: struct book
{
char title[20];
char author[15];
int pages;
float price;
}
ex: union item
{
int m;
float x;
char c;
}code;
ARRAYS
ARRAYS:
An array is a group of related data items that share a common name.For instance,we can define an array name salary to represent a set of
salaries of a group of employees. A particular value is indicated by writing a number called index number of subscript in brackets after the array name.
For example: salary[20];//salary contains maximum of 20 charaters
Array range will be 0 to n.
There are two types of arrays:
1.one dimentional arrays
2.two dimentional arrays
Array declration:
ex: int marks[20];
Entering data in array:
ex: for(i=0;i<=19;i++)
{
printf("\nenter marks");
scanf("%d",&marks[i]);
}
Reading data from an array:
ex: for(i=0;i<=19;i++)
sum=sum+marks[i];
a) An array is a collection of similar elements.
b) The first element in the array is numbered 0,so the element is 1 less than the size of the array.
c) An array is also known as a subscripted variable.
d) Before using an array its type and dimension must be declared.
More on Array(Array Initialisation):
ex: int num[6]={2,4,6,8,10,12};
int n[]={2,3,4,5,6};
float p[]={12.3,34.2};
Note:
a) Till the array elements are not given any specific values,they
are supposed to contain garbage values.
b) If the array is initailsed where it is declared mentioning the dimension of the
array is optional as in the 2nd example above.
Initialising A 2-Dimensional Array:
how to intialise atwo dimensional array?
int stud[4][2];
above initialisation tells that there will be 4 rows and 2 columns.
in other words 4 different numbers of students and thier marks and other thing should be 2 character.
ex: int stud[4][2]={{1234,56},{1345,67},{1456,78},{1567,90}};
it can be written i other form
ex: int stud[4][2]={1234,56,1345,67,1456,78,1567,90};
In Matrix Array is represented as:
ex: int a[3][3];// 3*3 3 rows and 3 columns
An array is a group of related data items that share a common name.For instance,we can define an array name salary to represent a set of
salaries of a group of employees. A particular value is indicated by writing a number called index number of subscript in brackets after the array name.
For example: salary[20];//salary contains maximum of 20 charaters
Array range will be 0 to n.
There are two types of arrays:
1.one dimentional arrays
2.two dimentional arrays
Array declration:
ex: int marks[20];
Entering data in array:
ex: for(i=0;i<=19;i++)
{
printf("\nenter marks");
scanf("%d",&marks[i]);
}
Reading data from an array:
ex: for(i=0;i<=19;i++)
sum=sum+marks[i];
a) An array is a collection of similar elements.
b) The first element in the array is numbered 0,so the element is 1 less than the size of the array.
c) An array is also known as a subscripted variable.
d) Before using an array its type and dimension must be declared.
More on Array(Array Initialisation):
ex: int num[6]={2,4,6,8,10,12};
int n[]={2,3,4,5,6};
float p[]={12.3,34.2};
Note:
a) Till the array elements are not given any specific values,they
are supposed to contain garbage values.
b) If the array is initailsed where it is declared mentioning the dimension of the
array is optional as in the 2nd example above.
Initialising A 2-Dimensional Array:
how to intialise atwo dimensional array?
int stud[4][2];
above initialisation tells that there will be 4 rows and 2 columns.
in other words 4 different numbers of students and thier marks and other thing should be 2 character.
ex: int stud[4][2]={{1234,56},{1345,67},{1456,78},{1567,90}};
it can be written i other form
ex: int stud[4][2]={1234,56,1345,67,1456,78,1567,90};
In Matrix Array is represented as:
ex: int a[3][3];// 3*3 3 rows and 3 columns
STANDARAD LIBRARY STRING FUNCTIONS
STANDARD LIBRARY STRING FUNCTIONS:
1)strlen()
2)strcpy()
3)strcat()
4)strcmp()
1)strlen(): which tells about the length of the string means number of characters in that string.it also count the spaces.
Ex: int len1,len2;
len2=strlen("kite fly in sky");
printf("\n string=%s length=%d","kite fly in sky",len2);
output:
string=kite fly in sky=15 // with count of spaces.
2)strcpy(): This function copies the contents of one string into another.
Ex: char source[]="kamesh";
char target[20];
strcpy(target,source);
printf("\nstring=%s",source);
printf("\nstring=%s",target);
output:
source string=kamesh
target string=kamesh
3)strcat(): this function concatenates the source string at the end of the target
string.
For ex: "Ashok" and "varama" on concatenation would result into a string "Ashokvarama".
Ex: char s[]="ashok";
char t[]="varama";
strcat(t,s);
printf("\nstring=%s",t);
output:
sourcestring = Ashokvarama
4)strcmp(): This is a function which compares two strings to find out whether
they are same or different. the two strings are compared character by character until there is a
mismatch or end of one of the strings is reached, whichever occurs first.if the two strings are identical,
strcmp() returns a value zero.if they're not,it returns the numeric
difference between the ascii values of the non-matching characters.
Ex: char s1[]="jerry";
char s2[]="ferry";
int i,j,k;
i=strcmp(s1,"jerry");
j=strcmp(s1,s2);
k=strcmp(s1,"jerry boy");
printf("\n%d%d%d",i,j,k);
output:
0 4 -32
1)strlen()
2)strcpy()
3)strcat()
4)strcmp()
1)strlen(): which tells about the length of the string means number of characters in that string.it also count the spaces.
Ex: int len1,len2;
len2=strlen("kite fly in sky");
printf("\n string=%s length=%d","kite fly in sky",len2);
output:
string=kite fly in sky=15 // with count of spaces.
2)strcpy(): This function copies the contents of one string into another.
Ex: char source[]="kamesh";
char target[20];
strcpy(target,source);
printf("\nstring=%s",source);
printf("\nstring=%s",target);
output:
source string=kamesh
target string=kamesh
3)strcat(): this function concatenates the source string at the end of the target
string.
For ex: "Ashok" and "varama" on concatenation would result into a string "Ashokvarama".
Ex: char s[]="ashok";
char t[]="varama";
strcat(t,s);
printf("\nstring=%s",t);
output:
sourcestring = Ashokvarama
4)strcmp(): This is a function which compares two strings to find out whether
they are same or different. the two strings are compared character by character until there is a
mismatch or end of one of the strings is reached, whichever occurs first.if the two strings are identical,
strcmp() returns a value zero.if they're not,it returns the numeric
difference between the ascii values of the non-matching characters.
Ex: char s1[]="jerry";
char s2[]="ferry";
int i,j,k;
i=strcmp(s1,"jerry");
j=strcmp(s1,s2);
k=strcmp(s1,"jerry boy");
printf("\n%d%d%d",i,j,k);
output:
0 4 -32
STRINGS
STRINGS:
The way a group of integers can be stored in an integer array, similarly a group of characters can be stored in a character array.
Character arrays are many a times also called strings.Programmers use character arrays or strings in programming languages to manipulate text such as words and
sentences.
A string constant is alone dimensional array of characters terminated by a null('\0').
Ex:
char name[]={'k','a','m','e','s','h','\0'};
the terminating null('\0') is important,because it is the only way the functions that work with a string can know where the string ends.
In fact, a string not terminated by a '\0' is not really a string,but
merely a collection of characters.
Ex: char name[]="kamesh";
Note that, in this declaration '\0' is not necessary.c inserts the null character automatically.
The way a group of integers can be stored in an integer array, similarly a group of characters can be stored in a character array.
Character arrays are many a times also called strings.Programmers use character arrays or strings in programming languages to manipulate text such as words and
sentences.
A string constant is alone dimensional array of characters terminated by a null('\0').
Ex:
char name[]={'k','a','m','e','s','h','\0'};
the terminating null('\0') is important,because it is the only way the functions that work with a string can know where the string ends.
In fact, a string not terminated by a '\0' is not really a string,but
merely a collection of characters.
Ex: char name[]="kamesh";
Note that, in this declaration '\0' is not necessary.c inserts the null character automatically.
POINTERS
POINTERS:
The pointer has a simple definition that is
A value which points towards the address of another value which is called as pointer.
Ex: int *p,a=10;
p=&a;
Here *p is a pointer where a is a variable.
here 'a' consists of a value "10" but p consists the address of
the 'a'.which means as we know the address we can know the value also.
The pointer has a simple definition that is
A value which points towards the address of another value which is called as pointer.
Ex: int *p,a=10;
p=&a;
Here *p is a pointer where a is a variable.
here 'a' consists of a value "10" but p consists the address of
the 'a'.which means as we know the address we can know the value also.
Subscribe to:
Posts (Atom)