-1

I know that !!(a.k.a. double bang) is used in C++ as a trick to convert to bool(like this)
But I was surfing on Politecnico of Milan and I've found this code:

int main() {
    char *p, s[6] = "DBPAY";
    int a = 3;
    p = s;
    printf("%c", *(p++));
    f( &p, a );
    printf("%c !!", *p);
    return 0;
}

void f(char ** c, int x) {
    void *z = &z;
    if( strlen(*c) < 2 )
        return;
    printf( "%c", (**c)+x );
    (*c)++;
    f( c, --x );
    return;
} 

It's a simple program about pointer arithmetic but I don't know what means:

printf("%c !!", *p);

Someone could explain what it does?

Community
  • 1
  • 1
Tinwor
  • 7,765
  • 6
  • 35
  • 56

2 Answers2

2
printf("%c !!", *p);

prints the character p points to, and some other characters, which are " !!" in this case. They are irrelevant.

2501
  • 25,460
  • 4
  • 47
  • 87
1
printf("%c !!", *p);

Is similar to

printf("%c",*p);
printf(" !!");

%c is the format specifier for a character and you print the character that the pointer points to. The asterisk tells to dereference the pointer. The space and the exclamation marks are the other characters which will be printed.

Spikatrix
  • 20,225
  • 7
  • 37
  • 83