//Void pointer used to store value of other variables y z etc in one another variable x etc #include <stdio.h> int main() { void *v; // int *p , *q; int x =10 , y; float avg = 12.12; char k = 'A'; v = &x; y = *((int *)v); printf("y=%d\n" , y); v=&k; printf("y = %c\n" , *(char *)v); v = &avg; printf("y= %f\n", *((float *)v)); return 0; }
/* we can change the value of variables by using pointer in two different ways first by pointer derefernce line no. 19 and second by line no 21*/ #include <stdio.h> int main(){ struct student { char name[70]; int age ; int rollno; }; struct student sumit = { "sumitbohare" , 18, 34}; struct student *ptr; ptr = &sumit; (*ptr).rollno = 35; //ptr -> rollno = 35; printf("%s, %d, %d ", sumit.name , sumit.age , sumit.rollno ); return 0; }
Comments
Post a Comment