answersLogoWhite

0


Best Answer

# include<stdio.h>

# include<conio.h>

void main()

{

clrscr();

int a,b;

printf ("Enter the first value:");

scanf ("%d",& a );

printf ("Enter the second value:");

scanf ("%d",& b );

printf ("\n\nBefor swaping the values ");

printf ("\nThe first value is %d",a);

printf ("\nThe second value is %d",b);

printf ("\n\nAfter swaping the values ");

printf ("\nThe first value is %d",b);

printf ("\nThe second value is %d",a);

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

You cannot swap functions, only variables. A function is not a variable.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Wap for swapping values of two variables using pointers as arguments to functions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the meaning of swapping in c?

Swapping has nothing to do with programming languages.


How do you write a c program to swap the values of two variables in unix?

#include&lt;stdio.h&gt; void main() { int a=2,b=4; printf("Program for swapping two numbers "); printf("Numbers before swapping"); printf("a=%d and b=%d",a,b); a=((a+b)-(b=a)); printf("Numbers after swapping"); printf("a=%d and b=%d",a,b); getch(); }


How do you swap two strings in c plus plus?

The most efficient way to swap strings is to point at them, and swap the pointers. Swapping the actual strings is problematic if the strings are of unequal length but impossible when they are also statically allocated. Dynamic strings can always be physically swapped, however it's highly inefficient. If it really must be done, then use a built-in method such as string::swap(). Otherwise just use string pointers and swap the pointers, never the strings themselves. The following example shows how both techniques can be used on statically allocated strings. Example output is show below. #include &lt;iostream&gt; using namespace std; void SwapPointers(char ** pp1, char ** pp2 ) { cout&lt;&lt;"\nSwapping pointers:"&lt;&lt;endl; char * t = *pp1; *pp1 = *pp2; *pp2 = t; } void SwapStatics(char * String1, char * String2, size_t len) { cout&lt;&lt;"\nSwapping static strings:"&lt;&lt;endl; while(len--) String1[len]^=String2[len]^=String1[len]^=String2[len]; } int main() { char s1[] = "one "; char s2[] = "two "; char s3[] = "three "; // Note that the output statements before and after // swapping are exactly the same, proving the strings // have really swapped. cout&lt;&lt;"Original strings:"&lt;&lt;endl; cout&lt;&lt;s1&lt;&lt;s2&lt;&lt;s3&lt;&lt;endl; SwapStatics(s1,s2,sizeof(s1)); cout&lt;&lt;s1&lt;&lt;s2&lt;&lt;s3&lt;&lt;endl; cout&lt;&lt;endl; // We cannot swap s3 with either s1 or s2, because // s1 and s2 don't have the space to accomodate s3. // However, we can use pointers instead: char * p1 = s1; char * p2 = s2; char * p3 = s3; // Again, note that the output statements are the // same before and after swapping, proving the // pointers have swapped. cout&lt;&lt;"Original pointers:"&lt;&lt;endl; cout&lt;&lt;p1&lt;&lt;p2&lt;&lt;p3&lt;&lt;endl; SwapPointers(&amp;p1,&amp;p3); cout&lt;&lt;p1&lt;&lt;p2&lt;&lt;p3&lt;&lt;endl; cout&lt;&lt;endl; // Just to prove the strings didn't swap... cout&lt;&lt;"The strings have not swapped:"&lt;&lt;endl; cout&lt;&lt;s1&lt;&lt;s2&lt;&lt;s3&lt;&lt;endl; cout&lt;&lt;endl; return(0); } Output: Original strings: one two three Swapping static strings: two one three Original pointers: two one three Swapping pointers: three one two The strings have not swapped: two one three


Program designed to swap the values of two variables?

You'll need 3 variables for this, here's a pseudo code for swapping values of 2 variables.ALGORITHM SWAPvar1 = 10var2 = 20temp = 0temp = var1 "temp = 10"var1 = var2 "var1 = 20, originally 10"var2 = temp "var2 = 10, originally 20"END SWAP


What is the flowchart for swapping two variables?

include#includevoid main(){int x, y, temp;printf("Enter the value of x and y ");scanf("d", &x, &y);printf("Before Swapping x = %d\ny = %d\n",x,y);temp = x;x = y;y = temp;printf("After Swapping x = %d\ny = %d\n",x,y);getch();return 0;}Do you happen to know what a flow-chart is?

Related questions

What is meant by swapping of variables?

It means that you swap the values of that variables EX: -==- before swapping :- Variable1 = 5; variable2 = 10; after swapping :- Variable1 = 10; variable2 = 5;


What is the advantage of swapping two variables without using 3 variable?

Nothing. Never do that.


What is hot-swapping hardware?

The Functions of replacing system components without shutting down the system


Swapping of two variables withou using temp variable?

example: x = x-y; y = y-x; x = y-x; &lt;&gt;&lt;&gt;&lt;&gt; It is not possible to swap two variables without using a temp variable. The code in the answer above, while clever, does not swap the variables. It will exchange the variable values for certain values of x and y, e.g. when x and y are small integers. If x and y are other values, such as strings, pointers, Infinity, NaN (not a number), floating point, or near the limits of the representation (causing over/underflow) then the code will not "swap" the values. &lt;---&gt; Note: there is absolutely no point in swapping two variables without using temopral variable, it's just a typical homework question, already asked here countless times. Another variation: a ^= b; b ^= a; a ^= b;


What is the purpose of swapping?

Swapping was an older form of memory management. It was moving from/to secondary storage a whole program at a time, in a scheme known as roll-in/roll-out. Now swapping is a fairly close synonym of paging.


How do you invert a lengthy column of poems so the last one is on top?

The most efficient way of inverting any collection is to work inwards from both ends of the collection, swapping elements until the pointers meet or pass one another.


What is the meaning of swapping in c?

Swapping has nothing to do with programming languages.


Differences between swapping and overlays?

1. In overlays there is no need for the whole program to reside in main memory .here if say if a program has two functions say f1(50k) and f2(70k) such that they are in mutual exclusion with each other then, the memory of only 70k will be allocated for both the functions and the one that is needed at a particular moment can reside in the main memory . this even saves the memory ,But it is not in case of swapping . here the whole program needs to reside in main memory 2. overlays require careful and time consuming planning while in swapping it is not needed 3. swapping needs to issue system calls for requesting and releasing memory which is not in case of overlays


What is swap in c?

swapping is nothing but interchanging the values of a given character for example : if a=5 , b=4 before swapping then it becomes a=4,b=5 after swapping


Is there wife swapping in china?

yes I'm sure there is wife swapping in china as theres file swapping at rapidbyte.org so why not step it up a gear and share your wife in china!


How do you write a c program to swap the values of two variables in unix?

#include&lt;stdio.h&gt; void main() { int a=2,b=4; printf("Program for swapping two numbers "); printf("Numbers before swapping"); printf("a=%d and b=%d",a,b); a=((a+b)-(b=a)); printf("Numbers after swapping"); printf("a=%d and b=%d",a,b); getch(); }


How do you swap two strings in c plus plus?

The most efficient way to swap strings is to point at them, and swap the pointers. Swapping the actual strings is problematic if the strings are of unequal length but impossible when they are also statically allocated. Dynamic strings can always be physically swapped, however it's highly inefficient. If it really must be done, then use a built-in method such as string::swap(). Otherwise just use string pointers and swap the pointers, never the strings themselves. The following example shows how both techniques can be used on statically allocated strings. Example output is show below. #include &lt;iostream&gt; using namespace std; void SwapPointers(char ** pp1, char ** pp2 ) { cout&lt;&lt;"\nSwapping pointers:"&lt;&lt;endl; char * t = *pp1; *pp1 = *pp2; *pp2 = t; } void SwapStatics(char * String1, char * String2, size_t len) { cout&lt;&lt;"\nSwapping static strings:"&lt;&lt;endl; while(len--) String1[len]^=String2[len]^=String1[len]^=String2[len]; } int main() { char s1[] = "one "; char s2[] = "two "; char s3[] = "three "; // Note that the output statements before and after // swapping are exactly the same, proving the strings // have really swapped. cout&lt;&lt;"Original strings:"&lt;&lt;endl; cout&lt;&lt;s1&lt;&lt;s2&lt;&lt;s3&lt;&lt;endl; SwapStatics(s1,s2,sizeof(s1)); cout&lt;&lt;s1&lt;&lt;s2&lt;&lt;s3&lt;&lt;endl; cout&lt;&lt;endl; // We cannot swap s3 with either s1 or s2, because // s1 and s2 don't have the space to accomodate s3. // However, we can use pointers instead: char * p1 = s1; char * p2 = s2; char * p3 = s3; // Again, note that the output statements are the // same before and after swapping, proving the // pointers have swapped. cout&lt;&lt;"Original pointers:"&lt;&lt;endl; cout&lt;&lt;p1&lt;&lt;p2&lt;&lt;p3&lt;&lt;endl; SwapPointers(&amp;p1,&amp;p3); cout&lt;&lt;p1&lt;&lt;p2&lt;&lt;p3&lt;&lt;endl; cout&lt;&lt;endl; // Just to prove the strings didn't swap... cout&lt;&lt;"The strings have not swapped:"&lt;&lt;endl; cout&lt;&lt;s1&lt;&lt;s2&lt;&lt;s3&lt;&lt;endl; cout&lt;&lt;endl; return(0); } Output: Original strings: one two three Swapping static strings: two one three Original pointers: two one three Swapping pointers: three one two The strings have not swapped: two one three