This program showing error due to format specifier I've used here while printing the array address in for loop. If I'm using any format specifier except %p for printing the address like %ld, %u, %d etc, it is showing error that are as follows :
prog.c: In function 'main':
prog.c:18:10: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'int *' [-Wformat=]
printf("Address arr[%d] is %ld\n", i, &arr[i]);
^
Here is my code :
// C program to demonstrate that array elements are stored
// contiguous locations
#include <stdio.h>
int main()
{
// an array of 10 integers. If arr[0] is stored at
// address x, then arr[1] is stored at x + sizeof(int)
// arr[2] is stored at x + sizeof(int) + sizeof(int)
// and so on.
int arr[5], i;
printf("Size of integer in this compiler is %lu\n", sizeof(int));
for (i = 0; i < 5; i++)
// The use of '&' before a variable name, yields
// address of variable.
printf("Address arr[%d] is %ld\n", i, &arr[i]);
return 0;
I am not able to understand why %p is used here and what can I use to make my program error free