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 the process to generate random numbers in c programming language?
How is = symbol different from == symbol in c programming?
What are the functions to open and close file in c language?
Difference between malloc() and calloc() function?
Difference between goto, long jmp() and setjmp()?
What is a char c?
Explain which function in c can be used to append a string to another string?
Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor
What is #include stdlib h?
What are the types of data files?
What is const and volatile in c?
What is cohesion and coupling in c?
Explain what header files do I need in order to define the standard library functions I use?
What is static and auto variables in c?
What does 2n 4c mean?