Functions in C | C Language Tutorial | Mr. Srinivas

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to Norwich technologies this is Wayne was in the last session so we had discussed so what is a variable and what is a function so these two are the main building blocks to develop application so to write a program now we will see how many classifications right of a method so generally only four method classifications are present so whatever the programming language you take so this is not only for C language C C++ Java dotnet wherever you go any textbook you open write any program you see if you look at one particular method or one particular function the function belongs to any one of these four classifications the first one no arguments no arguments and no written values function second one with arguments and no return values function third one with arguments and with written values function and the last one no arguments and with written values function these are the four classifications available for a method so before so discussing all these four classifications so first we need to remember once again what is a function a function is a set of instructions it is taking input arguments is called input arguments is called input after processing the input after processing the information right it will produce that output that return value we can call it as an output a function is a block of instructions is taking input technically arguments and after that it is processing that input using the predefined logic after processing it will produce that output so depends on the method syntax only so now we will discuss all these four classifications okay see four classifications here the first one we are writing no arts and no return values is a first classification second one with arcs and no return values third one with arcs with return values in the last one no arcs and with return values no arcs and with return values see the classification first classification no arms and no return values I am writing one function this function name I am taking fun it is a block of instructions we already discussed here you will write the logic the function logic we need to place inside this block any logic you can write the function is taking input is nothing but arguments here it is this is arguments place and this is a return values place but here it is what is our classification no arguments so here it is we need to write a no arguments and no return values and here also we are writing no but here it is instead of writing no they have given one technical keyword in the programming languages is called void void is representing no nothing so no arguments and no return values function a function is a block of instructions is not taking any arguments and not returning anything to anyone next come to that second classification with arguments no return values so function with arguments we need to pass some arguments we need to pass or humans sir what are the arguments of values integers float double character strings all these are comes under input types simply I am passing only one integer to collect that we are declaring one variable this is called arguments look at the classification ones with arguments so we need to pass arguments and next it will process that input with the predefined logic and finally it will return the output output is a void because no return values look at the classification function is taking arguments with arguments but it is not returning anything no return values is the classification second classification now come to the third classification with arguments and with return values classification a function function is taking arguments with arguments here it is suppose we are passing character any arguments we can pass sir how many arguments we can pass no limitations hundreds of hundreds of arguments we can pass depends on your application requirement so here it is simply I am passing only one argument character and here with return values so written statement mandatory suppose I am returning thirteen thirteen is of type what is an integer type so return type is a integer the function with arguments so here it is taking arguments what type arguments it is taking no matter first it is taking arguments or not that we have to consider so here it is is taking arguments and next what it is returning integer data it is returning with return values means return statement is compulsory it is mandatory to define so return statement thirteen it is returning thirteen is of what type of data integer data so return type is also integer and the last classification no arguments and with return values no arguments and with return values see here now fun no arguments means why'd we need to write wide with written values what it is returning suppose here it is written in the value three four point five six three four point five six is of type float type or double type so here it is a written type is also float type so classification no arguments and with return values only four classifications are present for a function or method these four classifications very easy to understand in every program from day one to day end right in every program we always define any one of these four methods only in any programming language so that much important for classifications clearly we can understand first one is a function with no arguments and no return values no means wide we are writing no arguments no return values second classification is a with arguments and no return values it is taking arguments but not returning anything third classification is with arguments and with return values is taking character and it is returning integer sir here it is is taking character Y it is returning integer sir there is no such restriction that what type of data it is taking it has to return the same type of data for example take away the draw operation with the draw operation means the input is a just pin number and how much amount you want to withdraw but output is an amount money but take a deposit function input is the money and output is just a received so there is no relation between input and output okay any function right can take different types of inputs and other types of outputs and the last classification is the function is not taking anything so written means what arguments type is a wide and returning is a flow type decimal value it is returning so float type so these are the four classifications so in our previous discussions it is clear that only definitions are present no use a functionality is there someone should call that functionality for example take this marker what is its functionality it is writing but will it write automatically no it will not write someone should access this functionality I am the person I am accessing this functionality so if only functionality is there no use someone should call from another place take the mobile so mobile is having so much functionality calling is one functionality best example will it call automatically no from another place some other person should call explicitly in the same way every function should have a definition along with the definition function call is also very very important a function call is not there right no use of definition if no one is using this markers functionality what is the use of this marker no use in the same way so here sir how to call a function here it is a four classifications are there right in four different ways we can call the functions how we will see again one by one okay see here it is how to call functions depends on the classification we are calling first function calling see function calling is always a single statement single statement means must ends with a semicolon suppose if you take of this function so this is what we question here it is no semicolon right here it is a open brace and close brace function definition means a block of instructions how many instructions are thousands of thousands of instructions you can write no limitations but function call is always a single statement that ends with the semicolon everything right here it is whenever you call this function is it expecting anything is it taking any input no so no need to pass anything here it is empty is it giving anything no it is not returning anything so here also it is also empty the function is not taking any input so no need to pass any input and it is not giving anything so no need to get anything is the first one and next to come to that second one function function and now what it is expecting the function definition is expecting an integer so you have to pass integer suppose if you want to perform deposit operation the bank personnel will expect some amount of money from you so that you have to pass so then only they can process that information so here it is whenever you call this function it is expecting integer so you have to pass that integer any integer you can pass suppose simply then I am passing 10 is an integer so that will go and store into X now X value 10 right then it will process the 10 but is it giving anything no it's not giving anything so no need to collect anything and next come to the third one function now what it is expecting it is expecting a character in any programming language we will represent characters using single quotes right so here it is if you want to pass character any character you can pass a special symbol also you can fast but we must place inside a single quotes suppose G I am passing right here it is we are placing in a single quotes so then whenever you call this function that G will go and store into variable X this is the value it will hold input is over now it is giving output output 13 it is giving 13 we should collect them into another variable or you can take a same variable also no problem but type is very very important so what type it is returning is very very important right here it is returning 1313 is of type integer type so we are collecting that result into integer type variable only for assignment operator always right side data executes first so right side data we are calling the function and we are passing the input character the character will go and store here and it is returning something so what type it is returning in teaser it is written in that integer data we are collecting into X X is of type integer because return type is integer and X the fourth classification suppose here we are calling the function fun is it expecting anything no type is a wide type so no need to pass anything to anyone but here it is we can expect something because it is returning a type three four point five six of type word float type so we should collect that into a variable of type of float type whether you are passing some values and someone is giving some output that we should collect into a variable but here it is we need to declare a variable of type what that is depends on the return type and here it is it is expecting character so you have to pass character value only and it is giving thirteen thirteen is an integer so you should collect into integer variable only here it is giving a float value so we are collecting into float type only here it is expecting integer value so here it is we are passing integer only so here it is a four classifications are present for every classification how to write the definition and how to call that function is clearly discussed only these four classifications available for every function remember only four classifications not only for C language in any programming language if you want to define a method you can define using any one of these four classifications only so that much important if you are perfect at all these four classifications then we can start programming so here it is in the next session we will see how to write a first C application thank you so thank you for watching and for more videos subscribe here
Info
Channel: Naresh i Technologies
Views: 1,406,450
Rating: 4.9085584 out of 5
Keywords: C Language, C Functions, Srinivas, Hands on C Language Training, C Language Interview Questions, Syntax of function, What is function, What is method, Function definition in C, Types of functions, Need of function, Use of function or method, Function definition, Function calling, Need of calling function, With arguments and With return values function, How function return values, functions in c, void keyword in c, declaration and definition in c, c functions tutorial
Id: TxWKGhF9KdM
Channel Id: undefined
Length: 16min 8sec (968 seconds)
Published: Sat Aug 27 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.