I have following code snippet in understanding the working of pointer to character array of specific length, with the following sample code.
#include <stdio.h>
int main(){
char sports[5][15] = {
"cricket",
"football",
"hockey",
"basketball"
};
char (*sptr)[15] = sports;
if ( sptr+1 == sptr[1]){
printf("oh no! what is this");
}
return 0;
}
How sptr+1
and sptr[1]
can be equal?As the first one means to increment the address,which is stored in sptr
by one and the second one means to get the value at address stored in sptr + 1
.