encyclopegia.org

Return type

In computer programming, the return type (or result type) defines and constrains the data type of the value returned from a subroutine or method. In many programming languages (especially statically-typed programming languages such as C, C++, Java) the return type must be explicitly specified when declaring a function. In the C example: int calculateSum(int a, int b) { return a + b; } the return type is . The program can therefore rely on the method returning a value of type . Various mechanisms are used for the case where a subroutine does not return any value, e.g., a return type of is used in some programming languages: void sayHello() { printf("Hello, world!"); }

In computer programming, the return type (or result type) defines and constrains the data type of the value returned from a subroutine or method. In many programming languages (especially statically-typed programming languages such as C, C++, Java) the return type must be explicitly specified when declaring a function. In the C example: int calculateSum(int a, int b) { return a + b; } the return type is . The program can therefore rely on the method returning a value of type . Various mechanisms are used for the case where a subroutine does not return any value, e.g., a return type of is used in some programming languages: void sayHello() { printf("Hello, world!"); } ==Returning a value from a method== A method returns to the code that invoked it when it completes all the statements in the method, reaches a return statement, or throws an exception, whichever occurs first. To declare a method's return type, it is included in its method declaration. Within the body of the method, the return statement is used to return the value. Any method declared void does not return a value. It does not need to contain a return statement, but it may do so. In such a case, a return statement can be used to branch out of a control flow block and exit the method and is simply used like this: return; If a value from a method declared is returned, a compiler error will occur. Any method that is not declared must contain a return statement with a corresponding return value, like this: return returnValue; The data type of the return value must match the method's declared return type; for instance, one cannot return an value from a method declared to return a . The method in the class that was discussed in the sections on objects returns an : class Rectangle { private int width; private int height; // ... // A method for computing the area of the rectangle public int getArea() { return width * height; } } This method returns the integer that the expression evaluates to. The method returns a primitive type. A method can also return a reference type. For example, in a program to manipulate objects, we may have a method like this: class Bicycle { // bicycle class } class RaceEnvironment { // environment class } public class BicycleRace { // ... public Bicycle playBicycleRace(Bicycle bike1, Bicycle bike2, RaceEnvironment env) { Bicycle winner; // Code to calculate which bike is // faster, given each bike's gear // and cadence and given the // environment (terrain and wind) return winner; } } ==References==

References

No reference rows published for this article.

Cite this article

MLA

"Return type." encyclopegia.org, 2025, https://encyclopegia.org/wiki/return-type. Accessed 24 November 2026.

Chicago

"Return type." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/return-type.

APA

encyclopegia.org. (2025). Return type. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/return-type

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Miami County

enwiki · references available

Christopher John Farley

enwiki · references available

Hematemesis

enwiki · references available

Melena

enwiki · references available

Tarim River

enwiki · references available

Serge Aubin

enwiki · references available

Portage la Prairie

enwiki · references available

Lop Nur

enwiki · references available

Rajōmon

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1319804395 · 0.5 · snapshot enwiki-001319804395

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.