Typecasting non-pointers in C
I'm rather new to programming and I know how to typecast pointers but I was having a little trouble typecasting non-pointers. Here is a sample piece of code which I think illustrates my question well.
Code:
#include <stdio.h> Code:
pointer_type5.c: In function ‘main’: |
There is an integer type called intptr_t defined in inttypes.h that can be safely used to hold a pointer (also there is an unsigned uintptr_t) type.
|
Quote:
|
Quote:
|
The correct thing to do was instead:
Code:
int int_array[5] = {1, 2, 3, 4, 5}; Code:
array_pointer++; Code:
printf("Address of element is: %p\n", array_pointer); Unless you need to, I would not have a pointer to an integer pointing to a character array. I've had instances where I need to convert a character to an integer, so what I'd do is something like this: Code:
char array_of_char[5] = { 'a', 'b', 'c', 'd', 'e' }; |
just to add
do you want to do type punning ? |
All times are GMT -5. The time now is 11:17 AM. |