Does return type only used for returning integer? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

Does return type only used for returning integer?

15th Mar 2018, 12:50 PM
Code Race
Code Race - avatar
6 Respuestas
+ 5
you can return Strings, intergers,double ect
15th Mar 2018, 1:08 PM
D_Stark
D_Stark - avatar
+ 4
Absolutely no brother, first of all, "RETURN IS NOT A DATA TYPE, IT'S A STATEMENT". which is used to shift the control to the line in program, from which place , you called the function. like: char function_name(char ch) { some code return ch; } int main() { cout << function_name('A'); return 0; } here, when we calling the function by passing 'A' as argument, control transferred to function. After some job, it comes to return statement, and returns ch. Then again comes to main function. That's the use of return statement. return can be used to return various things in any programming language. like it can be used to return data of primitive datatype. int, float, char, double, long, string, Boolean and so on. It can user-defined datatypes struct, union, pointer, ADT(stack, queue, and other DATA STRUCTURE constructs). it can be objects also, like some people's are already told. like : struct Stack{ int data; struct Stack *next; }S; struct Stack* INSERT(int x) { struct Stack* newNode = new struct Stack; newNode->data = x; newNode->next = S; return newNode; } int main() { S = INSERT(5); return 0; } here, you can see we are returning an ADT(Abstract Data Type) which is a user defined data. Now I guess, you understood, we can return other things also except integer. You have any doubt after that, you can ask.
19th Mar 2018, 1:22 PM
Ajay Agrawal
Ajay Agrawal - avatar
+ 3
No, you can return double, void, int....
15th Mar 2018, 1:01 PM
J.G.
J.G. - avatar
+ 2
You can return an data type, even objects you have created. The only aception is the main function which must return void or int.
15th Mar 2018, 1:10 PM
josh mizzi
josh mizzi - avatar
+ 1
it return double int float string etc
20th Mar 2018, 2:56 AM
MUHAMMAD WAQAS KHAN
MUHAMMAD WAQAS KHAN - avatar
+ 1
it can return any type of value depending on the type of the function
21st Mar 2018, 9:29 AM
Nirmal Kumar Singh