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
What is spark map function?
Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
What are header files in c programming?
Explain the properties of union.
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none
Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?
What are register variables? What are the advantage of using register variables?
Can you add pointers together? Why would you?
what are # pragma staments?
State two uses of pointers in C?
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
write a c program to calculate sum of digits till it reduces to a single digit using recursion
Explain how can you restore a redirected standard stream?
write a c program to find the sum of five entered numbers using an array named number
What is a 'null pointer assignment' error?