Write a program to swap 2 chars without using a third
varable?
char *s = "A";
char *p = "B";
Answer Posted / koushik sarkar
#include<stdio.h>
void swap(char *p,char *s){*p=*p+*s-(*s=*p);}
int main()
{
char a,b;
a='A';b='B';
printf("a=%c,b=%c",a,b);
swap(&a,&b);
printf("a=%c,b=%c",a,b);
return 0;
}
| Is This Answer Correct ? | 4 Yes | 11 No |
Post New Answer View All Answers
What flag means?
What is scope in c++ with example?
Is c++ a high level language?
If you don’t declare a return value, what type of return value is assumed?
Why namespace is used in c++?
Why is c++ considered difficult?
What is a block in c++?
What's the "software peter principle”?
What is a dangling pointer in c++?
What is main function in c++ with example?
How would you implement a substr() function that extracts a sub string from a given string?
Give the difference between the type casting and automatic type conversion. Also tell a suitable C++ code to illustrate both.
What is the benefit of encapsulation?
Who made c++?
Define what is constructor?