C# .NET - Numeric constants

Asked By Ismael on 12-Oct-11 12:23 PM

Please help me with this


QUESTION #1: NUMERIC CONSTANTS


Numeric constants are integers which range in magnitude from 0 to 999999999999999 and may be signed or unsigned. Examples of numeric constants are:

0 -13 1300 1 14567


Some invalid numeric constants are:


1.2

not an integer

$1

not numeric

1000000000000000

too large




Which of the following is not a legal numeric constant?


CORRECT

  • · A) 00000007
  • · B) -0
  • · C)10.2
  • · D) 89
dipa ahuja replied to Ismael on 12-Oct-11 12:26 PM
I think its C Because its float value
Ismael replied to dipa ahuja on 12-Oct-11 12:28 PM
I think so as well, but how can there be a -0
dipa ahuja replied to Ismael on 12-Oct-11 12:32 PM
hmm then may be both B & C.. 
Ismael replied to dipa ahuja on 12-Oct-11 12:47 PM
only one aswerrrrr, please help meee, which one
dipa ahuja replied to Ismael on 12-Oct-11 12:49 PM
Get it its C

Because when we write -0 its equals to 0

To Test :

int i = -0;
Response.Write(i.ToString());
This will print 0

So your answer will be C 10.2
Ismael replied to dipa ahuja on 12-Oct-11 12:51 PM
thanks
Suchit shah replied to Ismael on 12-Oct-11 01:06 PM
I would say answer is A because the reason is blank space is not allowded in numeric constant and if u check all other option then it follow the numeric constant rule....
what are the rules which are below 

The constant which consist of number digits and have least one digit, with no comma or space, with positive or negative sign and may or may not have decimal point (.) is called Numeric constant.

There are two types of two types they are;

  1. Integer constant

The whole numbers which have no faction part (decimal point) is called integer http://electronicsprogramming.com/uncategorized/constants/. There are three types of integer constant which are allowed in C are;

  1. Decimal constant ————–base 10.
  2. Octal constant——————-base 8.
  3. Hexadecimal constant———base 16.

 

The allowed digits under integer constant are;

0,1,2,3,4,5,6,7,8,9,10 ——————— Decimal constant.

0,1,2,3,4,5,6,7 —————————— Octal constant.

0,1,2,3,4,5,6,7,8,9,10 ——————— Hexadecimal constant.

A,B,C,D,E,F,a,b,c,d,e,f

 

#..Some valid decimal constant are;

0 , 1 , 19 , 672 , 9999, 30000

And following are the invalid decimal integer constants are;

18#3, 1(blank) 9, 55.5, 082, 182, 6, 7-4+56

In above example, character (#), blank space,(.) , (,),(-+) are illegal characters and 0 cannot be the first digits of decimal integer constants…

 

#..Octal integer constant stats from digits of set 0 to 7 but its digits must be starts for 0. For example;

0856

0

01

081102

So some invalid octal integers constant are;

4402————-Does not begin with 0.

0586————-8 is not an octal digits.

077.21———–Decimal point not allowed.

-0#76————-Illegal character (-, #).

 

#..A hexadecimal constant must have at least one hexadecimal digit and starts with ox or OX. It may have either + or – sign.

Some valid hexadecimal constants are;

OX52

OX89

-ox0725

+0x85210E

And some invalid hexadecimal constant are;

14AF—————–Does not begin with ox or OX.

OX 4905Bh ———‘h’ is not a hexadecimal digit.

0x.4bcde ———— Illegal character (.).

 

  1. Real constants or floating point.

A floating point constant is a base-10 numbers those constants either a fraction form or the exponent or the both. It may have either sign (+,-).

#..Some valid floating points are as given;

0.5 , 11.0 , 8905.2, 4000. , 66668e2 , -52.34 ,-o.123

#..The following are some invalid floating point constant;

85——————– Missing decimal point (.).

-1/2——————- Illegal characters(/).

.59,45.4—————Illegal character(.,,) and no digits to left of the decimal point.

 

#..Some valid floating pint constants in the exponent forms are given below.

8.85e5——is equivalent to 88500.

6.6E2——–is equivalent to 660.

5.3e-6——-is equivalent to -530000.


so According to this rule

  • · A) 00000007 ( but in option here there is 1st blankspace then it start with 0, if its not space then its octal constant but here the space is given so its invalid)
  • · B) -0  ( Decimal Constant as per rule +/- is optional)
  • · C)10.2 ( Floating point constant)
  • · D) 89 ( Decimal constant)


CORRECT ANS IS (A)

Devil Scorpio replied to Ismael on 12-Oct-11 01:16 PM
Hi Ismeal,

Constant means the value remain same from starting to end of a execution of program.

Constant can be variable , Fixed number or nething that remain same.

The following numeric constants are all legal numbers:

-3.4 .3 67.08E-10 6.3K 5N 1K_VOLT 1OO_OHM -1PI
I think everything is legal constant except -0, because there is no term/number like -0, its neutral. I think -0 is not a legal numeric constant.
Anoop S replied to Ismael on 12-Oct-11 04:05 PM
Numeric constants are integers which range in magnitude from 0 to 999999999999999 and may be signed or unsigned. (Hope you got answer if your above statement is correct)
Jitendra Faye replied to Ismael on 13-Oct-11 12:20 AM
Here c in correct answer.

Explanation

const int a= 00000007 ;   //no error

const int s= -0;      //no error

const int f =10.2;      //compile time  error

const int fa =89 ;    //no error

Try this and let me know.

Ismael replied to Ismael on 16-Nov-12 09:22 PM
x