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 are the advantages and disadvantages of c language?

0 Answers  


why r u join this company? give solid resons.

16 Answers   IBM, Infosys, TCS,


what is diognisis?

1 Answers  


How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

2 Answers  


write a program using linked list in which each node consists of following information. Name[30] Branch Rollno Telephone no i) Write the program to add information of students in linked list

0 Answers   Persistent,






Are pointers integers in c?

0 Answers  


At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with these names could be kept in that shelf as in this example: bottom of shelf ---> [AAAJKRDFDEWAAYFYYKK]-----Top of shelf. All these packets are to be loaded on cars. The cars are lined in order, so that the packet could be loaded on them. The cars are also named [A, B, C, D, E,………….]. Each Car will load the packet with the same alphabet. So, for example, car ‘A’ will load all the packets with name ‘A’. Each particular car will come at the loading point only once. The cars will come at the loading point in alphabetical order. So, car ‘B’ will come and take all the packets with name ‘B’ from the shelf, then car ‘C’ will come. No matter how deep in the shelf any packet ‘B’ is, all of the ‘B’ packets will be displaced before the ‘C’ car arrives. For that purpose, some additional shelves are provided. The packets which are after the packet B, are kept in those shelves. Any one of these shelves contains only packets, having the same name. For example, if any particular shelf is used and if a packet with name X is in it, then only the packets having names X will be kept in it. That shelf will look like [XXXXXXX]. If any shelf is used once, then it could be used again only if it is vacant. Packets from the initial shelf could be unloaded from top only. Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

0 Answers   Infosys,


What is openmp in c?

0 Answers  


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

0 Answers  


write a program for egyptian fractions in c?

1 Answers   Satyam,


when to use : in c program?

2 Answers  


Explain modulus operator. What are the restrictions of a modulus operator?

0 Answers  


Categories