Question

1. Instantiate pointers to various data types? How do you instantiate pointers to various data types?

1. Instantiate pointers to various data types? How do you instantiate pointers to various data types?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

   //a pointer of type int
   int * ptr1;
   //a pointer of type float
   float * ptr2;
   //a pointer of type char
   char *ptr3;
   int a=23;
   float b = 1.23;
   char c = 'P';
  
   //initialising pointer
   ptr1 = &a;
   ptr2 = &b;
   ptr3 = &c;
  
//Also we can use a void pointer

//a pointer of type void
   void * ptr;
   int a=23;
   float b = 1.23;
   char c = 'P';
  
   //initialising pointer
   ptr = &a;

printf("%d",(*(int*)ptr));
   ptr = &b;

printf("%f",(*(float*)ptr));
   ptr = &c;

printf("%c",(*(char*)ptr));

Add a comment
Know the answer?
Add Answer to:
1. Instantiate pointers to various data types? How do you instantiate pointers to various data types?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT