how to return 1000 variables from functio9n in c?plz give me
code also
Answers were Sorted based on User's Feedback
Answer / vignesh1988i
SEE /... we cant return 1000 variables at a time ... using
call by value...... only call by reference can do it....
tat is. usage of pointers...... since it will change
directly in the address itself.... that's a specality...
#include<stdio.h>
#include<conio.h>
void fun(int *,int *,int *.............1000 int's );
void main()
{
int a1,b1,c1,d1,.............a1000;
fun(&a1,&a2,...... &a1000);
for(int i=0;i<1000;i++)
printf("\n %d",a1);
getch();
}
void fun(int *a1,int *b2,.......... 1000 ptr declarations)
{
*a1=1;
*a2=2
.
.
.
.
.
.
100th varaible =1000;
}
| Is This Answer Correct ? | 9 Yes | 2 No |
Answer / ramachandran
#include<stdio.h>
int fun(int *a)
{
return ++(*a);
}
int main()
{
int a=0,i,d;
for(i=0;i<100;i++)
{
d=fun(&a);
printf("\n%d",d);
}
getch();
}
| Is This Answer Correct ? | 5 Yes | 1 No |
Answer / codee
extending the previous answer by passing array instead of
all variables
| Is This Answer Correct ? | 5 Yes | 2 No |
Answer / mishra@deepa
the first answer is quite long......
just pass an array(1000 elements) and return that.....
| Is This Answer Correct ? | 4 Yes | 2 No |
Answer / y hussain reddy
#include<stdio.h>
void main()
{
int *a;
a=(int*)malloc(200);
void f(int *);
f(a);
for(i=0;i<100;i++)
printf("%d ",a[i]);
}
void f(int *a)
{
int i;
for(i=0;i<100;i++)
a[i]=i;
}
| Is This Answer Correct ? | 0 Yes | 3 No |
Answer / vignesh1988i
you r right sir.... but he has asked 1000 VARIABLES.. so
only i done in this way.....
| Is This Answer Correct ? | 0 Yes | 4 No |
char ch="{'H','I',0};printf("%s",ch);what is output
What is unary operator?
program to find a smallest number in an array
Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.
Why header file is used in c?
Diff: between this 2 classes in terms of memory class A { int i; char c; double d; }; class A { double d; int i; char c; }; How it is calculating?
in malloc and calloc which one is fast and why?
What is alloca() and why is its use discouraged?
what would be the output of the follwing struct st { char name[20]; int i; float f; }; main() { struct st emp = {"forum"}; printf("%d %f",emp.i,emp.f); }
what is the output of the code and how? main() { int *ptr,x; x=sizeof(ptr); printf("%d",x); }
Why does not use getgh(); and <conio.h> in c language.
#define MAX 3 main() { printf("MAX = %d \n",MAX ); #undef MAX #ifdef MAX printf("Vector Instituteā); #endif