Closed.

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
re-publishing
boost this concern
monitor
asked Feb 18 "14 in ~ 15:38
*

user2274889user2274889
34111 yellow badge44 silver badges77 bronze badges
0
include a comment |

3 answers 3


energetic oldest Votes
33
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>).


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

DiptoDipto
2,61511 gold badge2020 silver- badges3838 bronze badges
3
add a comment |
12
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?


re-superstructure
improve this price
follow
answered Feb 18 "14 at 16:08
*

halfbithalfbit
3,14522 gold badges3030 silver- badges4242 bronze badges
include a comment |
1
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.


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

njzk2njzk2
37.5k66 gold badges6363 silver badges103103 bronze title
2
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
Linked
0
How to happen string/array to duty correctly? (stm32)
0
In C++ what walk it median to include a number come a buffer (i.e. Buffer+3)?
0
How to collection the atmosphere variable that child very same as parental to usage execve in C?
connected
3157
improve INSERT-per-second power of SQLite
1217
referral - What go this error average in PHP?
7
Assignment makes reminder from integer there is no a cast and also other inquiries
1
Warning: assignment renders integer from pointer without a actors
1
Why does the compiler problem "warning: assignment makes integer from reminder without a cast"?
warm Network inquiries much more hot inquiries
*

lang-c
ridge Overflow
assets
agency
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.