STRUCTURE OF C PROGRAM
Documentation section
Header section /#include<stdio.h>,<math.h>
Main() function/main()
{
Declaration part/int,float,…a,b,c,d;
Executable part /scanf(“%d%d%d”,&a,&b,&c);
D=a/b;
Printf(“d=%d”,d);
}
DATA TYPE
Char –hold one character and occupies one byte of space(‘A’,’*’,’8’,)
Int - hold integral quantities. Occupies 2byte of space ( int p, q,r;)
Float –hold floating point number . Occupies 4byte of space(float avg,)
Double- hold double floating point number . Occupies 8byte of space(float side, width;)
KEY WORDS
Auto, extern ,size of, break , floatn , static ,case, for, struct ,char, goto, switch,
Const,it,typedef,continue,int,union,default,long,unsinged,do,register,Void ,double ,return ,volatile ,else ,short , while ,else ,enum, signed.
ESCAPE SEQUENCE
A black slash followed by such a special character is called an ESCAPE SEQUENCE
1. \a - bell
2. \b – back space
3. \t – horizontal tab
4. \v – vertical tab
5. \n – new line
6.\f – form feed
7.\r- carriage return
8. \”-double quote
9.\? - question mark
0.\o-null
OPERATORS IN C
Arithmetic operators
Addition +
Subtraction –
Multiplication *
Division /
Modules % - reminder of operana1 divided by operand2
1.1 Relational operators
Equal ==
Greater than >
Less than <
Greater than or equal to >=
Less than or equal to <=
Not equal !=
1.2 Logical operator
AND &&
OR ||
NOT !
1.3 Assignment operators
Identifier = expression;
Identifier - represent a variable(x=7,p=q;)
Expression - represent a constant(x=y=4)
1.4 Increment and Decrement operators
Increment (++)
Decrement (--)
1.5 Conditional operator
Expression1? Expression 2:Expression3
1.6 Bitwise operators
& AND
| OR
^ x or
~ 1’s complement
>> shift right
<< shift left
1.7 special operators
Comma operator
Size of operator
Pointer operator
Member selection operator
HEADER FILES
#include<stdio.h>
The imprortant library functions covered by stdio.h header file are;
gets()
getchar()
put()
putchar()
scanf()
print()
READING A CHARACTER
getchar()
getche()
getch()
getc()
INPUT/OUTPUT FUNCTIONS
scanf()
printf()
programming
1.program to print name;
#include<stdio.h>
main()
{
clrscr();
printf(“INTO MAN\n”);
printf(“nest (h)\n”);
getch();
}
DECISION MAKING
if
if(expression)
statement
1.2 if-else
If (expression)
statement -1
else
statement -2
1.3 nested if
If (expression-1)
If (expression-2)
Statement -1
else
statement -2
else
if (expression-3)
statement-3
else
statement-4
1.4 go to
switch
LOOP STRUCTURES
while loop
while(expression)
statement
do-while loop
do
statement;
while(expression);
for loop
for((expression-1;expression-2;expression-3; statement;
while loop
-loop continuations conditions is checked at the beginning
-if the loop condition fails statement will not be executed at all
Do-while
-continuation condition is checked at the end
-statement will be executed at least ones
GLOBAL AND LOCAL VARIABLES
variables which are declared before the beginning of a function is called is called global variables. variables which are declared inside a function is called is called local variables
FUNCTION CALL
Function-name(argument-list);
Category of functions
functions with argument and return value.
functions with argument and no return value.
functions with no argument and no return values.
passing arguments to functions
call by value
call by references
ARRAYS
The individual data items in an array a are called array elements
1.1 ONE-DIMENSIONAL ARRAYS
data –type array name [expression];
1.2 TWO-DIMENSIONAL ARRAYS
Type array –name [row_ size] [column _size];
MULTI DIMENSIONAL ARRAYS
Array whose elements are specified by three or more subscripts are called multi dimensional arrays.
Data-type array-name[expressions1] [expressions2]…[expression3]
DYNANIC ARRAYS
Allocate memory to array at run time know as dynamic memory allocations and the arrays created at run time is called dynamic arrays.
STRING ARRAYS
A String is a group of characters .string is stored in an array of characters.
Char string-name[size];
STRUCTURES
A structure is collection of data item or variables of different data –types that is referenced under the same name
Struct tag-name
{
Data-type member1;
Data-type member2;
…………………………….
……………………………..
Data-type member n;
};
Unions
A union is syntactically the same as a structure .union is a construct that allows different type of data items to share the same block of memory,
union tag –name
{
member1;
member2;
…………….
……………..
};
Pointers
The variables that holds the address of a data item is called pointer.
Data-type*ptVar;
Malloc ()
Malloc() function is one of the most commonly used functions which permit allocation of memory form the pool of free memory. This function reserves a block of memory of specified size and returns a pointer of type void.
Ptr=(cast-type*)malloc(byte-size);
Ptr is pointer of type cast-type.
Calloc()
Calloc function is used for requesting memory space at run time for storing derived data type such as arrays and structure. While malloc() function allocates a single block of strong space ,calloc() allocates multiple block of storage, each of same size, and then sets all bytes to zero
Ptr=(cast-type*)calloc(n,elem-size);
STREAM
A stream is a sequence of byte of data .A sequence of byte following in to a program is an input stream and a sequences of byte flowing out of a program is an output stream.
TYPES OF FILES
. Standard (stream oriented)I/O text files
. Standard (stream oriented)I/O binary files
. Standard (stream oriented)I/O files.
OPENING A DATA FILE
FILE*ptvar;
Ptvar=fopen(“file name”,”mode);
CLOSING A DATA FILE
fclose (ptvar);
fprintf()and fscanf()
These functions are formatted i/o functions used to input/output the formatted data items .These functions can also handle a group of mixed data simultaneously ,fprintf and fsacnf functions behaves exactly like printf and scanf functions except that they operate with disk fils.
fprintf ( fp” control string”, argument list);
fscanf ( fp” control string”, argument list);
Documentation section
Header section /#include<stdio.h>,<math.h>
Main() function/main()
{
Declaration part/int,float,…a,b,c,d;
Executable part /scanf(“%d%d%d”,&a,&b,&c);
D=a/b;
Printf(“d=%d”,d);
}
DATA TYPE
Char –hold one character and occupies one byte of space(‘A’,’*’,’8’,)
Int - hold integral quantities. Occupies 2byte of space ( int p, q,r;)
Float –hold floating point number . Occupies 4byte of space(float avg,)
Double- hold double floating point number . Occupies 8byte of space(float side, width;)
KEY WORDS
Auto, extern ,size of, break , floatn , static ,case, for, struct ,char, goto, switch,
Const,it,typedef,continue,int,union,default,long,unsinged,do,register,Void ,double ,return ,volatile ,else ,short , while ,else ,enum, signed.
ESCAPE SEQUENCE
A black slash followed by such a special character is called an ESCAPE SEQUENCE
1. \a - bell
2. \b – back space
3. \t – horizontal tab
4. \v – vertical tab
5. \n – new line
6.\f – form feed
7.\r- carriage return
8. \”-double quote
9.\? - question mark
0.\o-null
OPERATORS IN C
Arithmetic operators
Addition +
Subtraction –
Multiplication *
Division /
Modules % - reminder of operana1 divided by operand2
1.1 Relational operators
Equal ==
Greater than >
Less than <
Greater than or equal to >=
Less than or equal to <=
Not equal !=
1.2 Logical operator
AND &&
OR ||
NOT !
1.3 Assignment operators
Identifier = expression;
Identifier - represent a variable(x=7,p=q;)
Expression - represent a constant(x=y=4)
1.4 Increment and Decrement operators
Increment (++)
Decrement (--)
1.5 Conditional operator
Expression1? Expression 2:Expression3
1.6 Bitwise operators
& AND
| OR
^ x or
~ 1’s complement
>> shift right
<< shift left
1.7 special operators
Comma operator
Size of operator
Pointer operator
Member selection operator
HEADER FILES
#include<stdio.h>
The imprortant library functions covered by stdio.h header file are;
gets()
getchar()
put()
putchar()
scanf()
print()
READING A CHARACTER
getchar()
getche()
getch()
getc()
INPUT/OUTPUT FUNCTIONS
scanf()
printf()
programming
1.program to print name;
#include<stdio.h>
main()
{
clrscr();
printf(“INTO MAN\n”);
printf(“nest (h)\n”);
getch();
}
DECISION MAKING
if
if(expression)
statement
1.2 if-else
If (expression)
statement -1
else
statement -2
1.3 nested if
If (expression-1)
If (expression-2)
Statement -1
else
statement -2
else
if (expression-3)
statement-3
else
statement-4
1.4 go to
switch
LOOP STRUCTURES
while loop
while(expression)
statement
do-while loop
do
statement;
while(expression);
for loop
for((expression-1;expression-2;expression-3; statement;
while loop
-loop continuations conditions is checked at the beginning
-if the loop condition fails statement will not be executed at all
Do-while
-continuation condition is checked at the end
-statement will be executed at least ones
GLOBAL AND LOCAL VARIABLES
variables which are declared before the beginning of a function is called is called global variables. variables which are declared inside a function is called is called local variables
FUNCTION CALL
Function-name(argument-list);
Category of functions
functions with argument and return value.
functions with argument and no return value.
functions with no argument and no return values.
passing arguments to functions
call by value
call by references
ARRAYS
The individual data items in an array a are called array elements
1.1 ONE-DIMENSIONAL ARRAYS
data –type array name [expression];
1.2 TWO-DIMENSIONAL ARRAYS
Type array –name [row_ size] [column _size];
MULTI DIMENSIONAL ARRAYS
Array whose elements are specified by three or more subscripts are called multi dimensional arrays.
Data-type array-name[expressions1] [expressions2]…[expression3]
DYNANIC ARRAYS
Allocate memory to array at run time know as dynamic memory allocations and the arrays created at run time is called dynamic arrays.
STRING ARRAYS
A String is a group of characters .string is stored in an array of characters.
Char string-name[size];
STRUCTURES
A structure is collection of data item or variables of different data –types that is referenced under the same name
Struct tag-name
{
Data-type member1;
Data-type member2;
…………………………….
……………………………..
Data-type member n;
};
Unions
A union is syntactically the same as a structure .union is a construct that allows different type of data items to share the same block of memory,
union tag –name
{
member1;
member2;
…………….
……………..
};
Pointers
The variables that holds the address of a data item is called pointer.
Data-type*ptVar;
Malloc ()
Malloc() function is one of the most commonly used functions which permit allocation of memory form the pool of free memory. This function reserves a block of memory of specified size and returns a pointer of type void.
Ptr=(cast-type*)malloc(byte-size);
Ptr is pointer of type cast-type.
Calloc()
Calloc function is used for requesting memory space at run time for storing derived data type such as arrays and structure. While malloc() function allocates a single block of strong space ,calloc() allocates multiple block of storage, each of same size, and then sets all bytes to zero
Ptr=(cast-type*)calloc(n,elem-size);
STREAM
A stream is a sequence of byte of data .A sequence of byte following in to a program is an input stream and a sequences of byte flowing out of a program is an output stream.
TYPES OF FILES
. Standard (stream oriented)I/O text files
. Standard (stream oriented)I/O binary files
. Standard (stream oriented)I/O files.
OPENING A DATA FILE
FILE*ptvar;
Ptvar=fopen(“file name”,”mode);
CLOSING A DATA FILE
fclose (ptvar);
fprintf()and fscanf()
These functions are formatted i/o functions used to input/output the formatted data items .These functions can also handle a group of mixed data simultaneously ,fprintf and fsacnf functions behaves exactly like printf and scanf functions except that they operate with disk fils.
fprintf ( fp” control string”, argument list);
fscanf ( fp” control string”, argument list);
No comments:
Post a Comment