By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,312 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,312 IT Pros & Developers. It's quick & easy.

What is return type?how can we use it?

P: 4
What is return type?how can we use it?
Aug 10 '10 #1
Share this Question
Share on Google+
4 Replies

P: 5
it is so complex a question . it accords to your needs and your definition. for example ,the funtion: int salary();then it will a type of integer .
Aug 10 '10 #2

Expert Mod 5K+
P: 9,197
The return type is used when you want your function to be an RVAL.

In this code:

Expand|Select|Wrap|Line Numbers
  1. int data = 10;
The 10 is an RVAL (the value is to the right of the = operator). data is the LVAL.

If the 10 need to be calculated, then you can use a function that returns an int:

Expand|Select|Wrap|Line Numbers
  1. int data = Calculate();
The compiler will call the function to get the int to assign to data. Calculate() is now an RVAL.
Aug 10 '10 #3

P: 542
Yes...and at its simplest it is demonstrated by functions.
Expand|Select|Wrap|Line Numbers
  1. int convert(double x)
  2. {x/=12;
  3. return x;}
double x is passed to convert(),converted to feet and returned as an int (the function type)
Aug 11 '10 #4

Expert 100+
P: 2,404
The starting point is with functions: what a function is and how it can be used. Let us know if you have questions about that.

Some languages (such as VisualBasic.NET, Pascal, Fortran, Ada) make a distinction between subroutines and functions. They consider a subroutine to be a callable block of code; while a function is a subroutine that also returns a value.

In C, both are called functions. However, a function that returns void is analogous to a subroutine.

You don't include a return value in a function definition for the fun of it -- you do it if and only if it makes sense to you for a value of some sort to be associated with the function. If you can't think of any useful value to return then define the function to return void.
Aug 11 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.