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 are types of preprocessor in c?
how to write a c program to print list of fruits in alpabetical order?
State two uses of pointers in C?
What is a const pointer in c?
What are the parts of c program?
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?
What is a node in c?
What is c preprocessor mean?
What is ## preprocessor operator in c?
Is exit(status) truly equivalent to returning the same status from main?
What does #pragma once mean?
please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com
What is meant by errors and debugging?
Explain can you assign a different address to an array tag?
How would you rename a function in C?