Can u return two values using return keyword? If yes, how?
If no, why?
Answer Posted / vikas shakya
Using the return statement u can only return one value at a
time.
So you can either return the value of a variable like you
can return an integer, or you can return pointer (which may
contain more than one values), which is pointing to
dynamically allocated location, Like in given below example:
//Returning two values from a function.
#include "stdio.h"
#include "malloc.h"
int *values()
{
int *ptr;
ptr = (int*)malloc(2);
*ptr = 10;
*(ptr+1) = 20;
return ptr;
}
int main()
{
int *ptr = values();
printf("%d\n%d",*ptr,*(ptr+1));
return 0;
}
| Is This Answer Correct ? | 2 Yes | 3 No |
Post New Answer View All Answers
how to write optimum code to divide a 50 digit number with a 25 digit number??
What are # preprocessor operator in c?
What is the c language function prototype?
Which is the memory area not included in C program? give the reason
What is union and structure?
What does c mean?
How do you define CONSTANT in C?
how to make a scientific calculater ?
Why do some versions of toupper act strangely if given an upper-case letter?
why programs in c are running with out #include
Explain what is output redirection?
What are header files? What are their uses?
What is function in c with example?
What is a constant?
Is c++ based on c?