Reputation: 45
I am wondering why the results turn out to be 100, 8, 1 in the output. 010 doesn't even make any sense that it is not 2 in binary digits. Am I missing something?
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int code[3];
code[0] = 100;
code[1] = 010;
code[2] = 001;
printf("%d\n", code[0]);
printf("%d\n", code[1]);
printf("%d\n", code[2]);
}
Upvotes: 0
Views: 55
Reputation: 619
100, 010 and 001 are not binary literals. 100 is a decimal literal; 010 and 001 are octal (base 8) literals. If you are using gcc there is an extension to support binary literals by using the prefix 0b
, as in
code[0] = 0b100; // evaluates to 4
Upvotes: 1