Give An Example Code Of A Snippet Function With And Without Parameters.

Give an example code of a snippet function with and without parameters.

Answer:

\tt\green{ }\huge{{\mathbb{Answer}}\pink{\small{\tt==========================}}}

Give an example code of a snippet function with and without parameters.

In this tutorial, we will learn functions in C programming. A function is a block of statements that performs a specific task. Let’s say you are writing a C program and you need to perform a same task in that program more than once. In such case you have two options:

  • a) Use the same set of statements every time you want to perform the task
  • b) Create a function to perform that task, and just call it every time you need to perform that task.

  • Using option (b) is a good practice and a good programmer always uses functions while writing code in C.

Why we need functions in C

Functions are used because of following reasons –

  • a) To improve the readability of code.
  • b) Improves the reusability of the code, same function can be used in any program rather than writing the same code from scratch.
  • c) Debugging of the code would be easier if you use functions, as errors are easy to be traced.
  • d) Reduces the size of the code, duplicate set of statements are replaced by function calls.

Types of functions

1) Predefined standard library functions

  • Standard library functions are also known as built-in functions. Functions such as puts(), gets(), printf(), scanf() etc are standard library functions. These functions are already defined in header files (files with .h extensions are called header files such as stdio.h), so we just call them whenever there is a need to use them.
  • For example, printf() function is defined in <stdio.h> header file so in order to use the printf() function, we need to include the <stdio.h> header file in our program using #include <stdio.h>.

2) User Defined functions

  • The functions that we create in a program are known as user defined functions or in other words you can say that a function created by user is known as user defined function.

  • Now we will learn how to create user defined functions and how to use them in C Programming

\rm\red{\overbrace{nderbrace{\tt\color{magenta}{\: \: \: \: \: \: \: \: \: \:  MyOwnAnswer \: \: \: \: \: \: \: \: \: \:}}}}

\rm\  \\ {\overbrace{nderbrace{\tt\color{blue}{\: \: \: \: \: \: \: \: \: \:  TrivinLangMalakas  \: \: \: \: \: \: \: \: \: \:}}}}

\tt\green{ }\huge{{\mathbb{----------------------------------}}\pink{\small{\tt==========================}}}


Comments