How to write a program for swapping two strings without
using 3rd variable and without using string functions.
Answer Posted / saptarshi
void main()
{
char *p="string1";
char *q="string2";
p^=q^=p^=q;
printf("%s,%s",p,q);
}
swapping the base pointers of the two strings may work...
if they are declared as character arrays, then it is not
possible as we cannot modify the value of array base
pointers...
Is This Answer Correct ? | 10 Yes | 26 No |
Post New Answer View All Answers
What is a function simple definition?
What is difference between class and structure?
What does %c do in c?
What are the types of data files?
Explain union.
What is function prototype in c language?
When should you not use a type cast?
Can we access array using pointer in c language?
how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?
Do pointers store the address of value or the actual value of a variable?
Why is sprintf unsafe?
main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }
main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }
What are the applications of c language?
Explain what are preprocessor directives?