Friday, April 6, 2012

Change value of a variable with out using pointer

Ques: Change value of a variable with out using pointer.
Boundary conditions
can only initalise the variable (variable whose value we want to change)and address operation can only be performed (&variable_name)
cannot use pointers variable.

here is an simple program
#include<conio.h>
 #include<stdio.h>
 int main(int argc, char *argv[])
 {
 int var=5,vptr;/*virtual pointer vptr*/
 clrscr();
 printf("value before operation:%d",var);
 vptr=(int)&var;
 *(int *)vptr=10;
 printf("value after operation:%d",var);
 getchar();
 return 0;
 }
its simple just use the type conversion trick.
thank you.bye.

Labels: , , , , , ,

how to add two pointers

hye, after a long time im writing a post.
todays topic is how to add two pointers.
its very simple and easy.
my college C teacher told me that you cannot add two pointers but after a while i got an idea how to do it.
before reading further i expect that you know type conversion.
 #include<conio.h>
 #include<stdio.h>
 int main(int argc, char *argv[])
 {
 int *a,*b;
 float c =(float)( (unsigned int)a + (unsigned int)b );/*address are unsigned integers( location are positive )*/
        clrscr();
 printf("%u + %u = %f",&a,&b,c);
 getchar();
 return 0;
 }
now if your teacher says that you cannot add two pointer,let him see the above code.:)
thank you bye.see you soon.

Labels: , , , , , ,