pic function notes
pic function notes
Function :- A function is a self content block of code or sub programs with a set of
statements that perform some specific task or coherent task when it is called as function.
(2) Reusability
Need of function :-
Types of functions :-
(1) Library functions :- In C, library functions are built-in functions that are
provided by the C Standard Library. These functions are pre-written and
compiled, so you can use them in your program without writing them from
scratch.
(2) User defined function :- In C, a user-defined function is a function that you
create yourself to perform a specific task. It helps organize code, make it
reusable, and improve readability.
Library functions :-
(1) Math function <Math.h> :- In C, math functions are a set of functions used to perform
common mathematical operations like square roots, trigonometric calculations,
powers, logarithms, etc. These functions are defined in the math.h header file.
Example:-
#include <stdio.h>
#include <math.h>
Int main() {
Double x = 9.0;
Return 0;
Example :-
Char ch;
Ch = getchar();
Example :-
Char ch = ‘A’;
Putchar(ch);
Malloc() (memory allocation) :- it gives you empty space in memory (dynamic memory).
Example :-
Int *ptr;
Calloc() (continuous allocation) :- Like malloc (), but it also sets memory to 0.
Example :-
int *ptr;
Function definition:- function definition consist of the world description and code of the
function. It tells about what function is doing what are it's inputs and what are its output. It
consist of two parts of function header and function body.
Syntax:-
Statement 1;
Statement 2;
Return value
Function declaration :- function declaration is also know as function prototype. Eat in form
the compiler about three thing, those name of the function, number and type of argument
received by the function and the type of value returned by the function.
Function call :- A function call when you tell the computer to run a function.
Example :-
#include <stdio.h>
Int main() {
Return 0;
}
Scope of variable :-
Function parameters :-
Function return type :- The function return type define the type of value that a function will
return to its caller. It's specified before the function name its declaration and definition.
Example :-
header file)
Return a + b;
Example :-
Void sayHello();
Void sayHello() {
Printf(“Hello!\n”);
Example :-
Return (x + y) / 2.0;
Example :-
Int* getPointerToValue() {
Recursive function :-A recursive function in C is a function that calls itself to solve a
problem. It’s commonly used for problems that can be broken down into smaller sub-
problems of the same type.
Example :-
#include <stdio.h>
Int factorial(int n) {
If (n == 0) {
Return 1;
} else {
Int main() {
Int number = 5;
Return 0;
Syntax :-
Void function(void);
Main()
{
Void function()
Statement;
Syntax :-
Int function,(void);
Main()
Int r;
r=fun();
Int fun()
return(exp);
Syntax :-
Main()
Int (a,b);
Statement;
}
Syntax :-
Fun(int,int);
Main()
Int r=function(a,b);
return (exp);