C Programming - Functions - Discussion

Discussion Forum : Functions - General Questions (Q.No. 1)
1.
The keyword used to transfer control from a function back to the calling function is
switch
goto
go back
return
Answer: Option
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

Discussion:
35 comments Page 3 of 4.

Madhu said:   1 decade ago
@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:   1 decade ago
How to work return function?

Kavya said:   10 years ago
Here value of a = 4, b = 3; then we are having calling function then a+b = 4+3 = 7.
(1)

Paras kaphalia said:   10 years ago
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?
(1)

Jubliant.9 said:   9 years ago
What is prototype? Please describe it.
(1)

Pranali said:   8 years ago
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:   8 years ago
@Rathika.

The answer is 3,3,1.

Gaurav kumar said:   8 years ago
Answer is 2, 2, 3.

Muniraja said:   8 years ago
Why to use return only condition is GOTO return value?

Niki said:   8 years ago
What is the protoype?


Post your comments here:

Your comments will be displayed after verification.