C Programming - Functions - Discussion

1. 

The keyword used to transfer control from a function back to the calling function is

[A]. switch
[B]. goto
[C]. go back
[D]. return

Answer: Option D

Explanation:

The keyword return is used to transfer control from a function back to the calling function.

Example:


#include<stdio.h>
int add(int, int); /* Function prototype */

int main()
{
    int a = 4, b = 3, c;
    c = add(a, b);
    printf("c = %d\n", c);
    return 0;
}
int add(int a, int b)
{
/* returns the value and control back to main() function */
   return (a+b);
}

Output:
c = 7


Klp; said: (Jan 13, 2011)  
Why 0 is there beside return ?

Balasubramanian.P said: (Mar 31, 2011)  
What is return function? how to understant that easily?

Sundar said: (Jun 13, 2011)  
@Klp

The return 0 in the main function transfers the control back to OS (DOS), and denotes that program exits successfully.

It may return 0 for successful completion, -1 to denote error occurred.

From your c program you can call another c program.

Example:

system("mypro.exe") - This function will return 0 on successful completion and -1 on error situation.

Sujatha said: (Aug 15, 2011)  
What is prototype? Explain in detail please.

Vishal said: (Aug 30, 2011)  
If any declearation is not persent in the original pattern then prototype error will occur.

Ex: If you type only print in turboc then it will show you print is a prototype or not specified the header file then also it will come such as if you use getch() without use of the #include<conio.h> header file (in turboc) then it will come getch() is a prototype.

Devdas said: (Oct 30, 2011)  
In simple way, return is a c-keyword used to transfer the control from called function to calling function. It can also use for return a single value.

Rathika.B said: (Dec 28, 2011)  
Please say what is the output of this program?

#include<stdio.h>
#include<conio.h>
void main()
{
int a=1;
printf("\n %d %d %d",a,a++,++a);
getch();
}

Santhosh Kumar said: (Jan 21, 2012)  
@Rathika
a=1
a++=1 //it increment the value after execute the exp
++a=3 //it increment the value before execute the exp

Kruthi said: (Jan 30, 2012)  
How goto works?

Vasavi said: (Feb 3, 2012)  
Goto leads to an unconditional jump in the execution flow of a program's code.

Mahesh Kharvi said: (Apr 2, 2012)  
0 is beside return because the function is integer type it should return integer value.

Tarun said: (Aug 23, 2012)  
We cannot write two arguments in the return statements

ex:
return(x,y);
it will take only 3

Robot said: (Aug 27, 2012)  
Tell me the difference between printf (predefined function) and return (keyword).

R@M said: (Sep 7, 2012)  
Relation between main function and called function is called "PROTOTYPE".

EX:- int add(int, int); /* Function prototype */

Mahesh said: (Sep 7, 2012)  
I think the answer is also may be relating to functions..
and finally what is the out put;
main(){
printf("Mahesh @ SVM");
main();

}

Vinny said: (Jan 16, 2013)  
What is difference between goto, return, go back and switch?

Raji said: (Mar 9, 2013)  
printf function can be used for print the statement and return keyword can be used for return the routine from called function to calling function declaration.

Vignesh said: (Apr 2, 2013)  
Function prototyping is nothing but we are declaring that we have a function in a specific name to the compiler.

Keerthana said: (Aug 7, 2014)  
What is notation?

Shiva Kumar Kella said: (Aug 8, 2014)  
@Ritika.
Answer is 1 and 1 and 3.

Explanation is :
Here is we have a command on post and pre increments.
Post increment :

1. First print the given number, and
2. Now increment itself by 1.

Pre increment :

1. First increment it self by 1, and
2. Now it's print what it have.

So ans ;1.a=1=> printed 1;

a++ => here printed 1 and incremented it self by 1 i.e. a=2;

++a => printed 3, because before a printing a will incremented by 1 ;

Madhu said: (Dec 8, 2014)  
@Mahesh.

You are right. Your output prints. But the general syntax of C program is:

int main () (...... return 0;}.

This may not be compulsory for GCC/Linux. But compulsory for Turbo C.

Tanu said: (Apr 9, 2015)  
How to work return function?

Kavya said: (Nov 13, 2015)  
Here value of a = 4, b = 3; then we are having calling function then a+b = 4+3 = 7.

Paras Kaphalia said: (Dec 29, 2015)  
Can goto set the program control outside the function? From outside the function I mean any other function the the one in which goto statement is used?

Jubliant.9 said: (Oct 14, 2016)  
What is prototype? Please describe it.

Pranali said: (Apr 1, 2017)  
Prototype should be given after the header file inclusion and before the main() function.
Using this we says to the compiler that 'that specific name'(ex. Fun()) will come in my program. ie it is nothing but pre declaration of that'fun' function.

There are three states of function:-

1). we declare prototype as- void fun(int,int); //compulsory to give semicolon
2). we call function as- fun(int,int) ; //no need to write return type of function
3). we define function as- void fun(int i, int j)
{
//code
}

Mushtaq Ahmed said: (Aug 24, 2017)  
@Rathika.

The answer is 3,3,1.

Gaurav Kumar said: (Sep 8, 2017)  
Answer is 2, 2, 3.

Muniraja said: (Nov 17, 2017)  
Why to use return only condition is GOTO return value?

Niki said: (Feb 9, 2018)  
What is the protoype?

Amreen said: (Jul 23, 2018)  
I need a clear explanation about calling a function. I want to know the methodology behind it. Could you please tell me?

Imran said: (Sep 28, 2018)  
I am not understanding the topic, so anyone help me to clear this topic.

Kirti said: (May 15, 2019)  
Can anyone explain me. How to decide Which code part we have to write in main block and function block? Please tell me.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.