Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

printf and character dilema

I have:

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

I know that the result is F, but why?
I don’t understand that [3]-1.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

"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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading