How to swap two variables, without using third variable ?
Answers were Sorted based on User's Feedback
Answer / er
Only #2 will work. The others may over/under flow.
| Is This Answer Correct ? | 83 Yes | 129 No |
Answer / ankush
using ref keyword we can swap 2 number's
emaple
class swap
{
public void add(ref int a,ref int b)
{
int z;
z=a;
a=b;
b=z;
}
}
class swapdemo
{
static void main()
{
int x=10,y=5;
ankush obj=new ankush();
Console.writeline{"befor value's"+a+","+b};
obj.swap(ref x, ref y);
Console.writeline("after values"+a+","+b);
}
}
| Is This Answer Correct ? | 13 Yes | 72 No |
Find your day from your DOB?
15 Answers Accenture, Microsoft,
how to check whether a linked list is circular.
int a=1; printf("%d %d %d",a++,a++,a); need o/p in 'c' and what explanation too
#include<conio.h> main() { int x,y=2,z,a; if(x=y%2) z=2; a=2; printf("%d %d ",z,x); }
main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }
main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }
How to read a directory in a C program?
#include<stdio.h> main() { register i=5; char j[]= "hello"; printf("%s %d",j,i); }
Write a program to print a square of size 5 by using the character S.
main(){ char a[100]; a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a); } abc(char a[]){ a++; printf("%c",*a); a++; printf("%c",*a); }
main() { float i=1.5; switch(i) { case 1: printf("1"); case 2: printf("2"); default : printf("0"); } }
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }