You are here:

C/Using pointer in C

Advertisement


Question
Hello,
I would like to have a question on a piece of code from this forum:
http://www.microchip.com/forums/m742195.aspx

Specifically,

uint8_t *array;
float adc = 1.23456;
array = ftoa( adc, ( int * ) 0 );

1. is uint8_t * array equivalent to char array[] ?
2. If so, it is not declared with size, so where does it end up in the memory ? There was no = new int[x] so it looks like there was no memory allocation.
3. What is the meaning of (int*) 0 ?
It looks like an int pointer that has zero address, so it would be a Null ? if so wouldn't it be an error when trying to reference null pointer ?

Thank you so much!
Ben

Answer
Hi Ben,

uint8_t is an unsigned eight bit type. The array variable in the code snippet you posted is a pointer to a uint8_t type. uint8_t and char are similar because they are both one byte in size. The implementation details of ftoa will tell you if the memory is allocated or if the memory ends up on the stack. It looks like the meaning of (int *)0 is to pass a null pointer as an argument to the function ftoa. The implementation of ftoa may allow for a null pointer and check for this, so it may or may not be an error.

-Tony

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tony Nazzal

Expertise

I will answer any c language programming and syntax questions.

Experience

I have almost a decade of c programming experience.

Education/Credentials
I have a bachelor of science degree and several years of industry experience.

©2016 About.com. All rights reserved.