473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why zero at the beginning of int variable gives error?

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     struct information
  6.     {
  7.         string  name;
  8.         string  bloodgroup;
  9.         int     mobno;
  10.     };
  11.  
  12.     information person1={"Ali Hamza","O-",434233434};
  13.     information person2={"Akram Ali","B",034};
  14.     cout << endl << person1.name << endl;
  15.     cout << person1.bloodgroup << endl << person1.mobno<< endl;
  16.     cout << endl << person2.name << endl << person2.bloodgroup << endl << person2.mobno<<endl;
  17.  
  18.     int bh = 09;
  19.     cout << bh;
  20.  
  21.     return 0;
  22. }
I wonder when I saw errors like invalid digit in octal constant 9 and 8.Also it print wrong value for the value of "mobno"(in structure) if zero is the first digit, but it give error when zero is used as first digit for num at the end of program.Is there someone who would explain it for me?
May 26 '15 #1

✓ answered by Rabbit

The reason is that numbers starting with a 0 is how you define an octal, base 8 number. Numeric data types can't store leading zeroes.

2 1252
computerfox
276 100+
I would suggest changing mobno to a string. Does the assignment require it to be an integer?
Usually contact information, including mobile numbers, are taken as strings.
May 26 '15 #2
Rabbit
12,516 Expert Mod 8TB
The reason is that numbers starting with a 0 is how you define an octal, base 8 number. Numeric data types can't store leading zeroes.
May 26 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Fie Fie Niles | last post by:
At our client site, when I tested a simple ASP page like the following: <%Session("test") = "this is testing"%> they got an error either "HTTP 500 page cannot be displayed" or "error '8002801d' ....
8
by: eje | last post by:
IsNumeric(value) should return false if value "can not be successfully converted to a Double." Instead I get the following error message: "Input string was not in a correct format." I use the...
6
by: vips | last post by:
Page_Load datagrid1.datasource=dataset1 //I am filling the datagrid and it works fine when page is displayed end ---------------
0
by: Pixie | last post by:
We are successfully getting a handle to a drive using createfile then using that handle to query the change journal using DeviceIOControl with the paramter FSCTL_QUERY_USN_DATA. However when we try...
12
by: arnuld | last post by:
in C++ Primer 4/3 Lippman says in chapter 3, section 3.3.1: vector<stringsvec(10); // 10 elements, each an empty string here is the the code output & output from my Debian box running "gcc...
6
by: ranesmitas | last post by:
Hi ,I am using Visual Basic Backend SQL I create form in which i create Command button NEW ,MODIFY, VIEW,SAVE,EXIT all my programme is running but when i add new record and save and then i...
2
by: kkshansid | last post by:
I dragged text box and write in data/control source = & "," & Chr$(13) & Chr$(10) & & Chr$(13) & Chr$(10) & but it gives error that #name? in layout view kindly help to resolve the problem...
0
by: rahulsankhe1089 | last post by:
I am using below javascript <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script> <script type="text/javascript"> ...
3
by: rahulsankhe1089 | last post by:
i have created web application in asp.net using visual studio 2010. i did coding in vb.net. in vb.net code i used simple message box. it does not give error when i run project through visual...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.