in Programming in C
482 views
0 votes
0 votes
Declare a function prototype which will do

1)recives two integer and float

2)return address of array of integers.

Please also explain it
in Programming in C
by
482 views

1 Answer

0 votes
0 votes

I think it is pretty straightforward.

int* functionName (int, int, float);

accepting the 2 integer and float parameters are self explanatory.

returning an array of integers can be accomplished by returning a pointer to the array.

But make sure the pointer which the function return is pointing to some array which is NOT declared in the local scope of this function. If it is so then the returned value may not point to the expected location.

1 comment

A small Correction in your statement

But make sure the pointer which the function return is pointing to some array which is NOT declared in the local scope of this function.

it should be the address pointed by the pointer which the function return is NOT declared in the local scope of this function.

for example:-

p1 is a global pointer and a1 is a global array

p2 is a local pointer and a2 is a local array

int * f()

{

     int *p2=a1;

     return p2; ------------- working fine 

}

int * f()

{

     int a2[100]={1,2,3,...100};

     p1=a2;

     return p1; ------------- gives error 

}

0
0

Related questions