C pointer query


Joined
Jul 18, 2014
Messages
1
Reaction score
0
I don't pointer and array arithmetic can any body will help me in all the details of pointer and array arithmetic along with examples programs.

Q1: Multiplication of pointer and unsigned integer is allowed how and why?
Q2: address of float can be assigned to a char pointer?
 
Ad

Advertisements

Joined
Feb 12, 2018
Messages
1
Reaction score
0
ans2.


You can indeed treat every object as an array of characters. However, you have to cast the pointer explicitly:

float f = 1.5f;

char const * p = (char const *)&f;

for (size_t i = 0; i != sizeof(float); ++i)
{
printf("The byte at position %zu has value %d.\n", i, (int)p);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top