Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
By Rajmal Menariya
address
State use of stack frame in function calls. Identify storage classes. Static and dynamic memory allocation
Functions in c
Need of functions : Repetitive Coding can be avoided functional organization of program structure Independent modules : therefore independent coding & debugging is possible.
Terms in relation with functions :
braces is followed by semicolon when a function is called the address of the next instruction is pushed on the stack stack is a data structure in memory which is used to execute functions when a function is called the control transfer from main() to the function definition stored in memory when the function execution is over the program control is again return back to main() by popping the address in the stack.
called function to the calling function then we use return statement. Return statement
returns calculated value to the calling function returns the control back to the calling function
time there may be multiple return statements present in a function but only one of them should be executed depending on the condition.
Pass by value
There are two argument passing mechanism to functions pass by value pass by address the information pass to the function is known as
argument the arguments that are passed at the time of function call are known as actual arguments the arguments that are collected in function definition are known as formal arguments actual & formal arguments are stored in different memory locations and they are treated as different variables by the compiler.
should be used.
of :
main ( ) Fn1 ( ) Fn2 ( ) Fn3 ( ) Fn9 ( ) Fn10 ( ) File A main prog file
Fn4 ( ) Fn 5 ( ) . File B
Fn6 ( ) Fn7 ( ) ..
File C
Code Section
Register
Local Within a fn call Garbage Registers Fn or { }
Static Within a function Through out prg Zero Data Section Within a function
Extern
Within a file Through out prg Zero Data Section Define 1 Declare n
array.
Strings i.e character arrays are used for text processing. Declaration for character array is char ArrName[size]; Every string ends with a \0 character whose ASCII value
is zero . Null character is automatically inserted by the compiler at the end of string. %s is the format specifier used for strings
returns 0 if strings are similar returns >0 if first is greater than another returns <0 if first is less than another
Need of structure
Array can store identical datatype elements
but reality demands something else e.g. student
Structure syntax,
structure declaration struct struct name { structure member 1; structure member 2; . }; memory is assigned at the time of structure variable
Structure I/O
Structure I/O can be using membership operator (.) using arrow pointer operator(->) e.g using membership operator scanf(format specifier,&structurename.membername); printf(format specifier,structurename.membername); e.g. using arrow pointer operator ptr is a structure pointer. scanf(format specifier,&ptr->membername); printf(format specifier, ptr->membername );
Structure pointer
Like any other pointer , structure can have a pointer
a structure pointer is a pointer which contains the base
address of structure variable for accessing structure members using pointers arrow pointer operator should be used on the left side of -> there should always be a structure pointer and on the right hand side there is structure member name
Function Pointer
Just as there are pointers to a variable, there are also pointers to
functions.
When a program is executed, the code of the function is stored in
memory.
A variable of the type, pointer to a function, stores the starting
Function Pointer
char (*ptr)();
// element is a pointer to a function, // which takes an int parameter and returns a void
//
Function Pointer
int main(){
void func1(), func2(); void (*ptr)(); // ptr is an array to //any function which returns void
ptr = func1;
void func1(), func2(), func3(); void (*ptr[3])();//ptr is array to any fn ptr[0] = func1; //initialize ptr with fn name
ptr[1] = func2;ptr[2] = func3;
(*ptr[i])();}
What is a list
linked list is a data structure which is used for
linked list is based on structure it uses self referential pointer distinguish between array & linked list
References
Jitendra Kumar Chauhan(Senior Consultant at C-DAC Noida
Let Us C++ Mastring in C++ http://embsysdesign.blogspot.com