swap (int *pa, int *pb) {
*pa ^= *pb;
*pa ^= *pa;
*pa ^= *pb;
}
int a,b; a=a+b; b=a-b; a=a-b; that's it simple
The required c program is given below /*Swapping(interchange) the two entered numbers*/ #include<stdio.h> main() { /*Without using third variable*/ int a,b,t; printf("Enter a:"); scanf("%d",&a); printf("Enter b:"); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\n After swapping without using third variable"); printf("\na=%d\nb=%d",a,b); }
yes we can run java program without using main. we can run program by declaring the variable static..
You can make use of pointers to achieve this.void add( int *a, int *b){(*a) += (*b);}Now if two numbers a and b are given and you need to store the value in variable c, then you would perform:c = a;add(&c,&b);
Ellipses (...) used to emulate indentation... swap (int *i1, int *i2) { /* only works for integers, i1 != i2 */ ... *i1 = *i1 ^ *i2; ... *i2 = *i1 ^ *i2; ... *i1 = *i1 ^ *i2; }
int a,b; a=a+b; b=a-b; a=a-b; that's it simple
A pointer is a variable used to store a memory address. That is, we can use a pointer variable to refer to another variable (including other pointers). Although many variables within a program have names and can be referred to directly by those names, the majority of variables are anonymous; they have no names we can refer to. For instance, every variable declared on the heap is anonymous, every element of an array is anonymous and every node in a list is anonymous. Without pointers there would be no way to refer to these anonymous variables. Moreover, there would be no way to allocate objects on the heap without pointers. Pointers also make it possible to pass addresses into functions. In C, for instance, all arguments to a function are passed by value, however a pointer's value is a memory address thus pointers allow us to use pass by reference semantics. This makes it possible for a function to refer to an object outwith the local scope of the function.
The required c program is given below /*Swapping(interchange) the two entered numbers*/ #include<stdio.h> main() { /*Without using third variable*/ int a,b,t; printf("Enter a:"); scanf("%d",&a); printf("Enter b:"); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\n After swapping without using third variable"); printf("\na=%d\nb=%d",a,b); }
They are pointers without type
yes we can run java program without using main. we can run program by declaring the variable static..
You can make use of pointers to achieve this.void add( int *a, int *b){(*a) += (*b);}Now if two numbers a and b are given and you need to store the value in variable c, then you would perform:c = a;add(&c,&b);
Ellipses (...) used to emulate indentation... swap (int *i1, int *i2) { /* only works for integers, i1 != i2 */ ... *i1 = *i1 ^ *i2; ... *i2 = *i1 ^ *i2; ... *i1 = *i1 ^ *i2; }
Yes. int a, b; a= 2; b= 3; a= a+b;
A = A xor B B = A xor B A = A xor B in C... A^=B; B^=A; A^=B;
In general, to swap two variables A and B with each other, you need a third variable T of the same type. You then perform the sequence T = A, A = B, and B = T. For the special case where A and B are binary types, you can swap them without a temporary variable using a bit-wise exclusive or operator. Using C/C++ syntax, you would use the sequence A ^= B, B ^= A, and A ^= B. For this to succeed, the exclusive or operator (^) must be bitwise. Actually, it is also possible to swap any two arbitrarily typed variables, such as float or object, so long as you can properly do the bitwise exclusive or operation, perhaps by doing typcasts or by playing games with pointers - although any of that is potentially dangerous and not always portable.
Because the laser pointers are much easier to use than the ball pointers. The ball pointers are often difficult to move around while the laser pointers can move in any direction without "getting stuck"
If you are talking about a class in Java, a variable encapsulated by a class is called an instance variable b/c everytime you create an object with that class, each object has its own set of the variables declared.