printf with “%d” of numbers starting with 0 (ex “0102”) giving unexpected answer (ex '“66”)

前端 未结 3 1130
青春惊慌失措
青春惊慌失措 2020-11-30 16:20

I used below code in my printf statement.

void main()
{
    int n=0102;
    printf(\"%d\", n);
}

This prints 66 as the answer. I also chang

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 16:35

    You tell printf to print the value in decimal (%d). Use %o to print it in octal.

提交回复
热议问题