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.?

Answers were Sorted based on User's Feedback



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++) prin..

Answer / 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

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++) prin..

Answer / masakali

2
4
6
8
10
16

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Interview Questions

What would happen to X in this expression: X += 15; (assuming the value of X is 5)

0 Answers  


Why static is used in c?

0 Answers  


Which one would you prefer - a macro or a function?

0 Answers  


What are the characteristics of arrays in c?

0 Answers  


Describe the header file and its usage in c programming?

0 Answers  






void main() { int x=25,y=32; clrscr(); x=x++ + y++; y=++x + ++y; printf("%d%d",x,y); }

5 Answers  


what is the difference between #include<stdio.h> and #include"stdio.h" ?

6 Answers   TCS,


how to implement stack operation using singly linked list

2 Answers  


What is console in c language?

0 Answers  


write a program to count the no of repaeted words in a line?

1 Answers  


what is d pitfalls of registers variables

3 Answers   TCS,


What is the collection of communication lines and routers called?

0 Answers  


Categories