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


Please Help Members By Posting Answers For Below Questions

Can a pointer be static?

611


What is the right way to use errno?

617


What is the acronym for ansi?

622


How can I convert a number to a string?

602


What is maximum size of array in c?

578






Is javascript based on c?

591


When the macros gets expanded?

780


What is variable in c example?

590


i got 75% in all semester am i eligible for your company

1730


Write a program for Overriding.

674


‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.

1872


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.

1842


What is the role of && operator in a program code?

564


Explain the ternary tree?

595


Can we assign integer value to char in c?

609