You are watching: Makes pointer from integer without a cast

This inquiry is not reproducible or was caused by typos. The is not right now accepting answers.
Want to improve this question? upgrade the inquiry so it's on-topic because that Stack Overflow.

Closed 7 year ago.

I"m having some trouble with pointers and arrays in C. Here"s the code:

#includeint *ap;int a<5>=41,42,43,44,45;int x;int main() ap = a<4>; x = *ap; printf("%d",x); return 0;When i compile and run the code I get this warning:

assignment makes tip from integer without a actors

For line number 9 (ap = a<4>;) and also the terminal crashes. If I adjust line 9 come not encompass a place (ap = a;) ns don"t get any type of warnings and also it works. Why is this happening? i feel favor the prize is obvious but I simply can"t check out it.

c arrays pointers warnings
boost this concern
asked Feb 18 "14 in ~ 15:38

34111 yellow badge44 silver badges77 bronze badges
include a comment |

3 answers 3

energetic oldest Votes
In this instance a<4> is the fifth integer in the array a, ap is a reminder to integer, for this reason you room assigning one integer come a pointer and that"s the warning. For this reason ap now holds 45 and also when you shot to de-reference it (by law *ap) you space trying to access a storage at resolve 45, which is an invalid address, for this reason your regime crashes.

You should do ap = &(a<4>); or ap = a + 4;

In c array names decays to pointer, so a points to the first element the the array.In this way, a is equivalent to &(a<0>).

boost this answer
edited Mar 27 "19 in ~ 16:03
answered Feb 18 "14 in ~ 15:41

2,61511 gold badge2020 silver- badges3838 bronze badges
add a comment |
What are you doing: (I am utilizing bytes instead of in for far better reading)

You start with int *ap and so on, so her (your computers) memory looks choose this:

-------------- memory supplied by part one else --------000: ?001: ?...098: ?099: ?-------------- her memory --------100: something lets take a look at waht happens as soon as (print brief cut for ...print("$d", ...)

print a<0> -> 41 //no surpriseprint a -> 101 // because a points to the begin of the arrayprint *a -> 41 // again the first element of arrayprint a+1 -> guess? 102print *(a+1) -> whats behind 102? 42 (we every love this number)and for this reason on, for this reason a<0> is the same as *a, a<1> = *(a+1), ....

a simply reads easier.

now, what wake up at heat 9?

improve this price
answered Feb 18 "14 at 16:08

3,14522 gold badges3030 silver- badges4242 bronze badges
include a comment |
int<> and also int* are stood for the exact same way, except int<> allocates (IIRC).

ap is a pointer, because of this giving that the worth of an essence is dangerous, as you have no idea what"s at deal with 45.

See more: Yu-Yu-Hakusho Juri Voice - Things I Like: Juri (Yu Yu Hakusho)

when you shot to accessibility it (x = *ap), you try to access address 45, which reasons the crash, together it most likely is not a component of the memory you have the right to access.

boost this answer
reply Feb 18 "14 in ~ 15:42

37.5k66 gold badges6363 silver badges103103 bronze title
include a comment |

Not the answer you're looking for? Browse other questions tagged c arrays needle warnings or asking your very own question.

The Overflow Blog
Featured ~ above Meta
How to happen string/array to duty correctly? (stm32)
In C++ what walk it median to include a number come a buffer (i.e. Buffer+3)?
How to collection the atmosphere variable that child very same as parental to usage execve in C?
improve INSERT-per-second power of SQLite
referral - What go this error average in PHP?
Assignment makes reminder from integer there is no a cast and also other inquiries
Warning: assignment renders integer from pointer without a actors
Why does the compiler problem "warning: assignment makes integer from reminder without a cast"?
warm Network inquiries much more hot inquiries

ridge Overflow
ridge Exchange Network
site architecture / logo © 2021 stack Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.11.11.40719

Stack Overflow works finest with JavaScript enabled

her privacy

By click “Accept all cookies”, you agree stack Exchange deserve to store cookie on your device and disclose details in accordance v our Cookie Policy.