I am new to C programming. Currently am trying to learn 3d array using pointers. Below is a program I am trying to debug. Can any one explain the difference between the two programs given below?
code1:
#include <stdio.h>
int main()
{
int a;
int d[2][2][2] = {1, -2, -3, 0, -9, -1, 3, -1};
printf("%d\n",*(*(*(d +1)+1)+1));
if(*(*(*(d +1)+1)+1) <(a= sizeof( int )))
puts(" u got it ");
else
puts (" but wrong");
return 0;
}
code2:
#include <stdio.h>
int main()
{
int a;
int d[2][2][2] = {1, -2, -3, 0, -9, -1, 3, -1};
if(*(*(*(d +1)+1)+1) <(sizeof( int )))
puts(" u got it ");
else
puts (" but wrong");
return 0;
}
In the first code I am getting the […incomplete…]
(size_t)-1isSIZE_MAX, which isn't smaller than the size of anint. The assignment in the first snippet converts thesize_tto anintso the left operand of<isn't promoted.size_tin this post, but I do seesizeof(int)which would probably be 4.sizeofoperator is of typesize_t, which is unsigned.-1 < sizeof(int): resultssizeofSince unsigned, -1 is compared by converting into unsigned.-1 < (a=sizeof(int)): results (a=sizeof(int)) Since signed(because type ofaissignedint).