为什么在打印数组元素时出现异常行为

时间:2019-06-16 12:03:21

标签: c

运行代码时出现意外结果。正如我期望的那样,此代码将按原样打印数组元素。但是对于前四个元素,我得到了不同的输出。为什么会这样?

#include<stdio.h>
void main()
{ int i,a[8]={000,001,010,011,100,101,110,111};
  for(i=0;i<8;i++)
  printf("%d",a[i]);
}

2 个答案:

答案 0 :(得分:3)

以数字0开头的

Integer constants八进制(以8为底)。文字010和011分别是值8和9。

答案 1 :(得分:0)

let path: String = Bundle.main.path(forResource: "DCH", ofType: "xlsx")! // Open the spreadsheet, get the first sheet, first worksheet, and first cell A1. // This is solely demo code to show basics; your actual code would do much more here. let spreadsheet: BRAOfficeDocumentPackage = BRAOfficeDocumentPackage.open(path) let sheet: BRASheet = spreadsheet.workbook.sheets[0] as! BRASheet let worksheet: BRAWorksheet = spreadsheet.workbook.worksheets[0] as! BRAWorksheet let cell: BRACell = worksheet.cell(forCellReference: "A1") // Print some info to show the code works. //print(worksheet.name) // print "Sheet1" print(cell.stringValue()) (不是let sheet: BRASheet = spreadsheet.workbook.sheets[0] as! BRASheet )指定八进制输出

"%o"

请参见ideone.com/Yy5yNA