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 1 of 4.

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
}

Shiva kumar kella said:   1 decade ago
@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 ;

Sundar said:   1 decade ago
@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.

Vishal said:   1 decade ago
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.

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.

Rathika.b said:   1 decade ago
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();
}

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

}

Raji said:   1 decade ago
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.

Devdas said:   1 decade ago
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.

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)


Post your comments here:

Your comments will be displayed after verification.