void main()
{int a[5],i,b=16;
for(i=0;i<5;i++)
a[i]=2*i;
f(a,5,b);
for(i=0;i<5;i++)
printf("\n %d",a[i]);
printf("\n %d",b);
}
f(int *x,int n,int y)
{
int i;
for(i=0;i<n;i++)
*(x+i)+=2;
y=y+2;
}wat r the errors in the prg.and improvise the prg to get o/p.?

Answer Posted / vignesh1988i

so , i can understand at first you are inputting
implicitally the values in the array using the variable
used in for loops... then you are changing the values again
by writing the function... sending the base address of the
array.. then only once the y value will get added by 2...
as for as me their is no error in your program... so ur o/p
will be :
2
4
6
8
10
16
BUT IN ORDER TO MAKE OUT THE VALUE OF 'Y' TO BE
INCREMENTED FOR EACH VALUE IN THE LOOP AND TRY TO MAKE
CHANGE DIRECTLY IN THE ADDRESS , make these corrections
f(a,5,&b); , f(int *x,int n,int *y) , the for loop may be
like this :
for(i=0;i<n;i++)
{
(*(x+i))=(*(x+i))+2;
(*y)=(*y)+2;
}
after this ur o/p will be :
2
4
6
8
10
26


thank u

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do you know what are bitwise shift operators in c programming?

589


Why does everyone say not to use gets?

612


What is #define?

578


What is exit() function?

565


Why do we use static in c?

636






Is that possible to store 32768 in an int data type variable?

694


How can I handle floating-point exceptions gracefully?

636


What are keywords in c with examples?

611


What does 2n 4c mean?

725


How do we make a global variable accessible across files? Explain the extern keyword?

1426


What is #line?

615


How can you increase the allowable number of simultaneously open files?

599


Difference between Function to pointer and pointer to function

636


Can you subtract pointers from each other? Why would you?

562


write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.

3343