different!!
#include <stdio.h>
#include <string.h>
int main(void)
{
char a[]="hello world";
char *b="hello world";
printf(" a6: %c\n", a[6]);
printf("a6+1: %c\n", a[6+1]);
printf(" b+6: %s\n", b+6);
*b++;*b++; /: for pro!
// b++; b++; // for gcc! & pro!
printf(" b++: %s\n", b);
printf(" b++: %c\n", b[0]); // NOTE
// the above last statement holds incremented pointer!!
printf(" b5: %c\n", b[5]);
printf("b5+1: %c\n", b[5+1]);
printf("la: %lu\n", strlen(a));
printf("lb: %lu\n", strlen(b));
printf(" %x\n", a[11]); // NULL/0: both
printf(" %x\n", b[9]); // 0
// printf(" %c\n", a[12]); // ERROR
// printf(" %c\n", b[25]); // NO-ERROR
// no-error in above line why?
}
Hoping GCC doesn’t throw any exception 😋
I’ve modified above program to show how increment works!! in pointers further..
line 14 - *b++;*b++; -> useless and insane. b++; b++; would be same but still insane. ++b; ++b; would be more efficient but insane. b += 2; would be sane. line 17 - // the above last statement holds incremented pointer!! - > statements don't hold incremented anything, variables do. line 26 - accessing pointer out of range, invalid line 27 - accessing pointer out of range, using invalid format specification, also invalid line 30 - it is an error. accessing pointer out of range
There aren't any exceptions in C
and this
Обсуждают сегодня