C# Multiple Choice Questions & Answers on Integer Data Types for Freshers

1. How many Bytes are stored by ‘Long’ Datatype in C# .net?

a) 8
b) 4
c) 2
d) 1
Answer: a

Explanation : ‘Long’ is the datatype keyword used for storing data of unlimited length so by definition its size is always maximum i.e 8.
2. Choose “.NET class” name from which datatype “UInt” is derived ?

a) System.Int16
b) System.UInt32
c) System.UInt64
d) System.UInt16
Answer: b

Explanation : By Defination class assigned to

a) System.Int16 = short.
b) System.UInt32 = UInt.
c) System.UInt64 = ULong.
d) System.UInt16 = UShort.
3. Correct Declaration of Values to variables ‘a’ and ‘b’?

a) int a = 32, b = 40.6;
b) int a = 42; b = 40;
c) int a = 32; int b = 40;
d) int a = b = 42;
Answer: c

Explanation : a) Although,declaration of ‘b’ and ‘a’ are correct but initialization of value to ‘b’ should be ‘int’ datatype not float.
b) Missing declaration type of ‘b’.
c) correctly declared datatypes ‘a’ and ‘b’.
d) ‘b’ can’t be assigned values before declaration.
4. Select error in the given program :
  1.  Static Void Main(String[] args)
  2.  {
  3.      const int m = 100;
  4.      int n = 10;
  5.      const int k = n / 5 * 100 * n ;
  6.      Console.WriteLine(m * k);
  7.      Console.ReadLine();
  8.  }
a) ‘k’ should not be declared constant
b) Expression assigned to ‘k’ should be constant in nature
c) Expression (m * k) is invalid
d) ‘m ‘ is declared in invalid format
Answer : b

Explanation :’k’ should be declared as const int k = 10/5 * 100*10 i.e only constant values should be assigned to a constant.

Output :Error 1 – The expression being assigned to ‘k’ must be constant.
5. Arrange the following datatype in order of increasing magnitude sbyte, short, long, int.

a) long < short < int < sbyte
b) sbyte < short < int < long
c) short < sbyte < int < long
d) short < int < sbyte < long
Answer : b
6. Which datatype should be more preferred for storing a simple number like 35 to improve execution speed of a program?

a) sbyte
b) short
c) int
d) long
Answer: a

Explanation : Wider datatype like int,long takes more time for manipulation of a program.
7. Which Conversion function of ‘Convert.TOInt32()’ and ‘Int32.Parse()’ is efficient?

1) Int32.Parse() is only used for strings and throws argument exception for null string
2) Convert.Int32() used for datatypes and returns directly ‘0’ for null string

a) 2
b) Both 1,2
c) 1
d) None of the mentioned
Answer: a

Explanation: Convenient for every datatype so mostly preferred.
8. Correct way to assign values to variable ‘c’ when int a=12, float b=3.5,int c;

a) c = a + b;
b) c = a + int(float(b));
c) c = a + convert.ToInt32(b);
d) c = int(a + b);
Answer: c
9. Correct Set of Code for given data ‘a’ and ‘b’ to print output for ‘c’ as 74 ?
a)
  1.    int a = 12;
  2.    float b = 6.2f;
  3.    int c;
  4.    c = a / b + a * b;
  5.    Console.WriteLine(c);
b)
  1.    int a = 12;
  2.    float b = 6.2f;
  3.    int c;
  4.    c = a / convert.ToInt32(b) + a * b;
  5.    Console.WriteLine(c);
c)
  1.    int a = 12;
  2.    float b = 6.2f;
  3.    int c;
  4.    c = a / convert.ToInt32(b) + a * convert.ToInt32(b);
  5.    Console.WriteLine(c);
d)
  1.     int a = 12;
  2.     float b = 6.2f;
  3.     int c;
  4.     c = convert.ToInt32(a / b + a * b);
  5.     Console.WriteLine(c);

Answer: c

Explanation:Usage of typecasting operation. Seperately check each expression taking typecast operations in concern.

Output : 74.
10) Does the output remain same or different for both cases?
1)
  1.   char l ='k';
  2.   float b = 19.0f;
  3.   int c;
  4.   c = (l / convert.ToInt32(b));
  5.   Console.Writeline(c);
2)
  1.    char l ='k';
  2.    float b = 19.0f;
  3.    int c;
  4.    c = Convert.ToInt32(l / b);
  5.    console.writeline(c);
a) Yes
b) No
Answer : No

Output – 1) 5.
2) 6.
11. Default Type of number without decimal is ?

a) Long Int
b) Unsigned Long
c) Int
d) Unsigned Int
Answer : c
12. Correct output for code is?
  1.  static void Main(string[] args)
  2.  {
  3.      float a = 10.553f;
  4.      long b = 12L;
  5.      int  c;
  6.      c = Convert.ToInt32(a + b);
  7.      Console.WriteLine(c);
  8.  }
a) 23.453
b) 22
c) 23
d) 22.453
Answer : c

Explanation:The two datatype ‘float’ and ‘long’ after arithmetic operation completely converted to nearest whole number 23.

Related

Java Multiple Choice Questions & Answers on Try & Catch for Freshers

1. What is the use of try & catch? a) It allows us to manually handle the exception.b) It allows to fix errors.c) It prevents automatic terminating of the program in cases when an exception occ...

Java Multiple Choice Questions & Answers on Inheritance – Abstract Class and Super for Freshers

1. Which of these keywords are used to define an abstract class? a) abstb) abstractc) Abstractd) abstract class Answer: b 2. Which of these is not abstract? a) Threadb) AbstractListc) Listd) Non...

Java Multiple Choice Questions & Answers on Command Line Arguments for Freshers

1. Which of these method is given parameter via command line arguments? a) main().b) recursive() method.c) Any method.d) System defined methods. Answer: a Explanation: Only main() method can be g...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item