Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

0 (ศูนย์) ใน C++ คือ Decimal Literal หรือ Octal Literal?

บทนำ

0 (ศูนย์) นำหน้าตัวเลข คือ Octal Literal

ใน C/C++ ใช้ octal literal โดยพิมพ์ 0 นำหน้าตัวเลขจริง เช่น เลขฐานแปด 25 เขียนเป็น 025

ตัวอย่างโค้ด

#include <stdio.h>
int main() {
    int a = 025;
    int b = 063;
    printf("Decimal of 25(Octal) is %d\n", a);
    printf("Decimal of 63(Octal) is %d\n", b);
    return 0;
}

ผลลัพธ์

Decimal of 25(Octal) is 21
Decimal of 63(Octal) is 51