Way to Defined Functions in C Language

WAY TO DEFINED FUNCTIONS





EXAMPLE OF -- "TAKES NOTHING RETURNS NOTHING"






NOTE-- 


The add() function takes input from the user i.e a&b and displays it on the screen. The empty parentheses in add() statement inside the main () function indicates that no argument is passed to the function.

The return data type of the function is void. which indicates no value is returned from the function.(void is empty data type

2-TAKES SOMETHING AND RETURNS NOTHING


type of function in c,example of function in c
example of function in c 



NOTE -

As we know that variables declaration in a function can not be accessed in any other function, but we want that if the data in the variable created in the main function is accessed in the add function, then at the time when compiler call the add function we have to pass the variable in its parenthesis  i.e x,y as shown in above example ,  when the add function is created, then the variable has to be declarated in parentheses i.e int a,int b


type of function in c,function call in c
function call in c


type of function in c,function call in c
call by function



NOTE -- 

we have discuss the function defined and funtion calling ,now in above example we see how to declare a function . Remember that funtion declaration alway declared either in body of  main () or before main() as we see in above example .

3-TAKES NOTHING AND RETURNS SOMETHING





The empty parentheses in s=add() statement indicates that no argument is passed to the function. And, the value returned from the function is assigned to s.
Here, the add() function takes input from the user and returns it.the value which return by return keyword is goes exactly where the function is called .

NOTE :--   

Remember, the return keyword will return only one value and after return keyword no instruction will run because cursor or control will also return with value  ,data type of value that we will return will be used when we create  an add function and we will also use that data type while declaring the function and will write 'void' in parentheses at the time of function declaration  because it's take nothing and return something nature.


4-TAKES SOMETHING AND RETURNS SOMETHING



The input from the user is passed to add() function.
The add() function  passed argument and return the value of c .The return value is assigned to s variable.

Then, main() function display the value of s.

Comments

Popular posts from this blog

Notepad, Wordpad and Paint

HOW TO PASS CCC EXAM WITH ONE ATTEMPT (NIELIT)

Inheritance in C++ Language(part 1)