Function

 https://drive.google.com/file/d/1U9sYX33X1tzGqnRMbrnUuXQB8uJjbJlk/view?usp=sharing

https://drive.google.com/file/d/1f1UYWItGjVoDHo9WeLqDm7nRWLRlVePB/view?usp=sharing

https://drive.google.com/file/d/1AwqJEzzMaoQL_F9ufOQExdYWtukgc430/view?usp=sharing

https://drive.google.com/file/d/1RAwKTsnjgfyRETxpiCMuNGkIFWZtfpSm/view?usp=sharing

https://drive.google.com/file/d/13fcVGyU0koFNKebqKrIw2EzuWNn_PawE/view?usp=sharing

 PST-pdf                    Instagram                              Twitter                        YouTube

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{

}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}

--------------------------------------------------------------------------------------------------------------------

1. INTRODUCTION  PST-PDF

-------------------------------------------------------------------------------------------------------------------

2. OPERATORS   PST-pdf

-------------------------------------------------------------------------------------------------------------------

3. LOOPING  PST-pdf

------------------------------------------------------------------------------------------------------------------

4. CONDITIONAL  PST-pdf

------------------------------------------------------------------------------------------------------------------

5. JUMPING STATEMENTS PST-pdf

------------------------------------------------------------------------------------------------------------------

6. ARRAY  PST-pdf

------------------------------------------------------------------------------------------------------------------

6. FUNCTION

------------------------------------------------------------------------------------------------------------------

7.1 Function

A function is a block of code that performs a particular task.

✔ There are many situations where we might need to write same line of code for more than once in a program.
✔ This may lead to unnecessary repetition of code, bugs and even becomes boring for the programmer.
✔ So, C language provides an approach in which you can declare and define a group of statements once in the form of a function and it can be called and used whenever required.

These functions defined by the user are also know as User-defined Functions

C functions can be classified into two categories,
✔ Library functions
✔ User-defined functions

Library functions are those functions which are already defined in C library, example printf(), scanf(), strcat() etc. You just need to include appropriate header files to use these functions. These are already declared and defined in C libraries.

A User-defined functions on the other hand, are those functions which are defined by the user at the time of writing program. These functions are made for code reusability and for saving time and space.


For Programming Training:
DM me Instagram

✔ It provides modularity to your programs structure.
✔ It makes your code reusable.
✔ You just have to call the function by its name to use it, wherever required.
✔ In case of large programs with thousands of code lines, debugging and editing becomes easier if you use functions.
✔ It makes the program more readable and easy to understand.

Function Declaration Syntax:
returntype functionName(type1 parameter1, type2 parameter2,...);

✔ Like any variable or an array, a function must also be declared before its used.
✔ Function declaration informs the compiler about the function name, parameters is accept, and its return type.
✔ The actual body of the function can be defined separately.
✔ Its also called as Function Prototyping.

Function declaration consists of 4 parts.
returntype
function name
parameter list
terminating semicolon

returntype
When a function is declared to perform some sort of calculation or any operation and is expected to provide with some result at the end, in such cases, a return statement is added at the end of function body. Return type specifies the type of value(int, float, char, double) that function is expected to return to the program which called the function.

Note: In case your function doesnot return any value, the return type would be void.

functionName
Function name is an identifier and it specifies the name of the function. The function name is any valid C identifier and therefore must follow the same naming rules like other variables in C language.

parameter list
The parameter list declares the type and number of arguments that the function expects when it is called. Also, the parameters in the parameter list receives the argument values when the function is called. They are often referred as formal parameters.


For Programming Training:
DM me Instagram

 call by value is the default way of calling a function in c programming.
lets understand the terminologies that we will use in call by value.

actual parameters: the parameters that appear in function calls.
formal parameters: the parameters that appear in function declarations.
✔ when we pass the actual parameters while calling a function then this is known as function call by value.
✔ in this case the values of actual parameters are copied to the formal parameters.
✔ thus operations performed on the formal parameters don’t reflect in the actual parameters.



for programming training:
DM me Instagram
  
The Call by reference method of passing arguments to a function copies the address of an argument into the formal parameter.
✔ Inside the function, the address is used to access the actual argument used in the call.
✔ It means the changes made to the parameter affect the passed argument.
When we call a function by passing the addresses of actual parameters then this way of calling the function is known as call by reference.
✔ In call by reference, the operation performed on formal parameters, affects the value of actual parameters because all the operations performed on the value stored in the address of actual parameters.

For Programming Training:
DM me Instagram

 Library functions in C language are inbuilt functions which are grouped together and placed in a common place called library. We are including these header files in our C program using “#include” command to make use of the functions those are declared in the header files.

Library Functions in stdio.h
☞ printf()
☞ fopen()
☞ freopen()
☞ fclose()
☞ feof()
☞ ferror()
☞ putc()
☞ fgetc()
☞ fputc()
☞ fflush()
☞ fgetpos()
☞ fprintf()
☞ fputs()
☞ fread()
☞ fseek()
☞ fsetpos()
☞ ftell()
☞ fwrite()
☞ getc()
☞ snprintf()
☞ getchar()
☞ putchar()
☞ puts()
☞ remove()
☞ rename()
☞ rewind()

List of Most used Header Files
☞ stdio.h
☞ conio.h
☞ string.h
☞ stdlib.h
☞ math.h
☞ time.h
☞ ctype.h
☞ stdarg.h
☞ signal.h
☞ setjmp.h
☞ locale.h
☞ errno.h
☞ assert.h


For Programming Training:
DM me Instagram

 User Define Functions are those functions which are defined and declared by the programmer to do some specific task. These are designed to re-use the code.

Benefits:
Using functions, you can divide your large program into small pieces according to different task which will provide you easy access to read and debug. Using functions, you can re-use your code. You do not need to rewrite the code, just call the function and use it. Using functions, you can modularize your code.

Declaration:
return-type functionName(type-of-local-argument-list);

Define:
return-type functionName(type-of-local-argument-list);
{
Function-body/ set-of-statements;
}

Calling an User Define Functions
functionName(actual-argument-list);

return-type
It is the data type of function’s return value. If function does not return value, function’s return type must be void. void is a data type which represent nothing i.e. function will not return any value.

functionName
It is the name of those set of statements which are written in function’s body. functionName can be any valid identifier’s name, please do not use any reserve word as a function name.

type-of-local-argument-list
List of the data type of those arguments (parameters) which are using in the function definition.

actual-argument-list
List of those parameters/ arguments, which are being passed in calling function.


For Programming Training:
Dm me Instagram

---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
BCA                                        PST & Programming C                                   Allrounder Sita Ram Sahu
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
>

No comments:

Post a Comment