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

What are types of preprocessor in c?

827


how to write a c program to print list of fruits in alpabetical order?

2080


State two uses of pointers in C?

853


What is a const pointer in c?

893


What are the parts of c program?

866


how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

1705


What is a node in c?

749


What is c preprocessor mean?

1050


What is ## preprocessor operator in c?

838


Is exit(status) truly equivalent to returning the same status from main?

843


What does #pragma once mean?

945


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

1583


What is meant by errors and debugging?

881


Explain can you assign a different address to an array tag?

867


How would you rename a function in C?

829