C pointers and arrays: [Warning] assignment makes pointer from integer without a cast -


I have some problems with pointers and arrays in C. Here's the code:

  Add # & lt; Stdio.h & gt; Int * 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'd compiled code runs, I get a warning:

[warning] integer without assignment, artists Indicator [enabled by default]

line number 9 (AP = A [4];) and for terminal crash. If I change the line 9 then I do not get any warning to include the situation (AP = A;) and it works. Why is this happening? I think the answer is obvious but I can not see it

In this case A [4] to 4th a , ap is an indicator for the integer, therefore you are assigning an integer for an indicator and this is the warning.
AP now 45 does and when you try to refer to it ( * ap ) to access a memory 45 address Trying to do that is an invalid address, so your program crashes.

You should do ap = & (one [4]); or AP = A + 4;

In the c the array name decreases the indicator, hence the a for the first element of the number array. In this way, a and (a [0]) are equal to .


Comments