write a function to swap an array a[5] elements like a[0] as
a[5],a[1] as a[4],....a[5] as a[0].without using more than
one loop and use one array not to use temp array?



write a function to swap an array a[5] elements like a[0] as a[5],a[1] as a[4],....a[5] as a[0].wit..

Answer / ashutosh tiwari

void arr_rev(int *arr, int size)
{
int i;
for(i=0;i<(size/2);i++)
{
if(i==size/2)
break;
*(arr+i) = *(arr+i) + *(arr+(size-i-1));
*(arr+(size-i-1)) = *(arr+i) - *(arr+(size-i-1));
*(arr+i) = *(arr+i) - *(arr+(size-i-1));
}
}

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More C Interview Questions

How can I remove the leading spaces from a string?

0 Answers  


how to write a c program to print list of fruits in alpabetical order?

0 Answers  


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

6 Answers   TCS,


difference between semaphores and mutex?

1 Answers  


Code for calculating square root without using library function, of math.h

4 Answers   IBM,


Explain what?s happening in the first constructor: public class c{ public c(string a) : this() {;}; public c() {;} } How is this construct useful?

1 Answers  


Describe explain how arrays can be passed to a user defined function

0 Answers  


please give me answer with details #include<stdio.h> main() { int i=1; i=(++i)*(++i)*(++i); printf("%d",i); getch(); }

3 Answers  


What is meant by type specifiers?

0 Answers  


how does a general function , that accepts an array as a parameter, "knows" the size of the array ? How should it define it parameters list ?

2 Answers   Patni, TCS,


Which node is more powerful and can handle local information processing or graphics processing?

0 Answers  


What is function pointer and where we will use it

2 Answers   Infosys, NetApp,


Categories