Question

Consider the following code snippet. What will be printed by *ptr and ptr after the lines...

Consider the following code snippet. What will be printed by *ptr and ptr after the lines shown. Explain with screenshots.

int a[4] = { 8, 3, 5, 6};

int *ptr = a;

ptr ++;

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

Code Snippet


   int a[4] = { 8, 3, 5, 6};
   int *ptr = a;
   ptr ++;

Break-down


   int a[4] = {8, 3, 5, 6};   //   array a is holding set of integers.

   int *ptr = a;           //   pointer ptr is containing the value of a (base address of array a).

   ptr ++;               //   pointer pts is incremented to its next position in array.


Output

   The ptr will first print the base address of the array, if used with * operator (like *ptr) it will print the value at first position in array i.e 8.


   After incrementing it is moved one step ahead and it will print next value in the array i.e 3.

Add a comment
Know the answer?
Add Answer to:
Consider the following code snippet. What will be printed by *ptr and ptr after the lines...
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
ADVERTISEMENT