Validity of struct statement.

Is the below statement valid or invalid.
Explain answer in either case.

 
  classList[20].pID = 000011100;
Last edited on
depends on amoun of elements classList contains, type of pID and do the programmer really intended to write number 4672 in it.
It could be valid, or it could be invalid, there is not enough information provided to answer the question.
correct i do ge the output as 4672. Why?
pID is of type 'int' and classList has [50] components in it.
http://en.cppreference.com/w/cpp/language/integer_literal
octal-literal is the digit zero (0) followed by zero or more octal digits (0, 1, 2, 3, 4, 5, 6, 7)
All numbers starting with 0 threated as written in octal system
Great!. Got it. So getting back to my original question the statement is Invalid.
Thanks a lot.
What is your compiler telling you?
complier outputs 4672, if i try to read that number with leading zero in an 'int' variable and then output the same.
So your compiler says the expression is valid, no error or warning messages, and the output appears to be correct for the value provided. So it appears to be a valid line of code. But just because it's a valid line of code doesn't mean it's doing what you intend.

What are you expecting the output to be?

i do want the output to be 000011100 because that is what was stored in classList[20].pID.
that is what was stored in classList[20].pID.
pID contains int. int is an abstract number. As there is no difference in 01 apple or 1 apple, there is no difference between 000011100 and 11100. You cannot say seeing 2 apples on a table if you should write 2 or 0000002 on a list, so ccannot compiler. You need to tell that explicitely: http://ideone.com/abSgEA
Topic archived. No new replies allowed.