Home > Mobile >  Printf and character dilema
Printf and character dilema

Time:01-31

I have the following piece of code:

#include <stdio.h> 
int main() {
    printf("%c","ACEGIK"[3] - 1); 
    return 0; 
}

I know that the result is F.

What does the [3] -1 mean ?

CodePudding user response:

"AGECIK" is an array of chars

you're taking the third element (counting from 0) "ACEGIK"[3] that's G

subtracting 1 'G' - 1 and getting character F


[3] is applied to the array

while -1 is applied to character/value got from the array

  • Related