-3
#include <stdio.h>
#include <conio.h>

int main()
{
    int *arr[]={1,2,3,4,5};
    printf("%d\n%d",**arr,**(arr+1));
    return 0;
}

I am getting a warning like initialization makes pointer form integer without a cast actually i don't know how pointers works for char and int. any suggestion will yield my knowledge. thanks for any help in advance.

Paul R
  • 208,748
  • 37
  • 389
  • 560
mrigendra
  • 1,472
  • 3
  • 19
  • 33
  • 4
    Please get a basic text book on C and study it, and write a few simpler programs first, before returning to Stack Overflow. While specific programming problems are fine for questions, asking for an outright tutorial is probably not within the scope of this site. – Kerrek SB Sep 05 '13 at 22:05
  • Declare arr as `int arr[] = {1,2,3,4,5};` Then use *arr, and *(arr+1). – dcaswell Sep 05 '13 at 22:08
  • Books are not sufficient without discussion or asking, even if the topic is so trivial like this. – mrigendra Sep 05 '13 at 23:13
  • Regarding `**arr` ,`**(arr+1)` read: [What does sizeof(&array) return?](http://stackoverflow.com/questions/15177420/what-does-sizeofarray-return/15177499#15177499) – Grijesh Chauhan Sep 06 '13 at 05:07

1 Answers1

1

int *arr[] declares an array of pointers to integers.

Since you are trying to initialize the array (which is of int-pointers) with integers, you receive the warning 'initialization makes pointer from integer without a cast'.

To be able to initialize your array with the values 1 to 5 as in your question, you need to declare your array to be of integers.

mxsscott
  • 403
  • 3
  • 8
  • #include #include int main() { int arr1[]={1},arr2[]={2},arr3[]={3},arr4[]={4},arr5[]={5}; int *arr[]={arr1,arr2,arr3,arr4,arr5}; printf("%d\n%d",**arr,**(arr+1)); return 0; } – mrigendra Sep 05 '13 at 23:07
  • Thanks i got your point and found my fault. – mrigendra Sep 05 '13 at 23:09