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
Can a pointer be static?
What is the right way to use errno?
What is the acronym for ansi?
How can I convert a number to a string?
What is maximum size of array in c?
Is javascript based on c?
When the macros gets expanded?
What is variable in c example?
i got 75% in all semester am i eligible for your company
Write a program for Overriding.
‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.
stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.
What is the role of && operator in a program code?
Explain the ternary tree?
Can we assign integer value to char in c?