Can u return two values using return keyword? If yes, how?
If no, why?
Answer Posted / vignesh1988i
ya we can return two or more than two values..... it's
possible..
by using concept of POINTERS..... but no need of return
keyword at all.....
instead of call by value in the function use call by
reference concept....
take the following program:
int fun(int *,int *);
void main()
{
int j=800,k=1000;
fun(&j,&k);
printf("%d",j,k);
getch();
}
int fun(int *q,int *w)
{
q=q/2;
w=w/2;
}
the output of the followiung is : 400 & 500.
how it's possible, i ll explain,
since we are calling by reference we
are sending the address of the two variables. so in fun.
definition we are catching it by pointers..... so that
pointer variable is holding the address of the two variables
in main fun. which is passed through address.... so in the
function we are changing the values of j & k.... so this
will change the value directly in the address of those two
variables j & k....... so implicitely two values are
returned wit out return keyword....
| Is This Answer Correct ? | 7 Yes | 9 No |
Post New Answer View All Answers
A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none
1) write a program to generate 1st n fibonacci prime numbers using Nested if 2) write a program to generate twin prime numbers from m to n using nested if 3) write a program to check whether a given integer is a strong number or not using nested if 4) Write a program to generate prime factors of a given integer using nested if 5)write a program to generate prime numbers from m to n using nested if 6)write a program to generate perfect numbers from m to n using nested if 7)write a program to generate the pallindromes from m to n using neste if 8)write a program to generate armstrong numbers from m to n using nested if 9)write a program to generate strong numbers from m to n using nested if
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
What is #pragma statements?
Explain what are bus errors, memory faults, and core dumps?
What is a spanning Tree?
write a program to display all prime numbers
What is the difference between a function and a method in c?
What does #pragma once mean?
What is the general form of a C program?
What is scope rule of function in c?
Why is it usually a bad idea to use gets()? Suggest a workaround.
How can I rethow can I return a sequence of random numbers which dont repeat at all?
How can I get back to the interactive keyboard if stdin is redirected?
what is ur strangth & weekness