* Vs ++ precedence in C

前端 未结 4 1174
名媛妹妹
名媛妹妹 2021-01-24 03:44

I am not able to understand the output of the following C code :

#include
main()
{
   char * something = \"something\";
   printf(\"%c\", *someth         


        
4条回答
  •  有刺的猬
    2021-01-24 04:08

    See http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence for details

    printf("%c", *something++);
    

    Gets the char at *something and then increments it ('s')

    printf("%c", *something);
    

    Just get the char (now the second, due to the increment in the last statement ('o')

    printf("%c", *++something);
    

    increment and then get the char of the new position ( 'm' )

    printf("%c", *something++);
    

    Gets the char at *something and then increments it ('m')

提交回复
热议问题