C# Questions & Answers – Integer Data Types

This section of our 1000+ C# multiple choice questions focuses on various data types in integer in C# Programming Language.

1. How many Bytes are stored by ‘Long’ Data type in C# .net?
a) 8
b) 4
c) 2
d) 1
View Answer

Answer: a
Explanation: ‘Long’ is the data type 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 data type “UInt” is derived?
a) System.Int16
b) System.UInt32
c) System.UInt64
d) System.UInt16
View Answer

Answer: b
Explanation: By Definition class assigned to
i) System.Int16 = short.
ii) System.UInt32 = UInt.
iii) System.UInt64 = ULong.
iv) 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;
View Answer

Answer: c
Explanation: i) Although, declaration of ‘b’ and ‘a’ are correct but initialization of value to ‘b’ should be ‘int’ data type not float.
ii) Missing declaration type of ‘b’.
iii) correctly declared data types ‘a’ and ‘b’.
iv) ‘b’ can’t be assigned values before declaration.
advertisement
advertisement

4. What will be the error in the following C# code?

  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
View Answer

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:

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
Error 1 - The expression being assigned to 'k' must be constant.

5. Arrange the following data type 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
View Answer

Answer: b
Explanation: By definition.
advertisement

6. Which data type 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
View Answer

Answer: a
Explanation: Wider data type like int, long takes more time for manipulation of a program.
advertisement

7. Which Conversion function of ‘Convert.TOInt32()’ and ‘Int32.Parse()’ is efficient?

i) Int32.Parse() is only used for strings and throws argument exception for null string
ii) Convert.Int32() used for data types and returns directly '0' for null string

a) ii
b) Both i, ii
c) i
d) None of the mentioned
View Answer

Answer: a
Explanation: Convenient for every data type 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);
View Answer

Answer: c
Explanation: None.

9. What will be Correct Set of C# 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);
View Answer
Answer: c
Explanation: Usage of typecasting operation. Separately check each expression taking typecast operations in concern.
Output :

 74
 
 

10. Does the output remain same or different for both cases?
i)

  1.   char l ='k';
  2.   float b = 19.0f;
  3.   int c;
  4.   c = (l / convert.ToInt32(b));
  5.   Console.Writeline(c);

ii)

  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
View Answer

Answer: b
Explanation:
Output –

         1) 5.
         2) 6.

11. Default Type of number without decimal is?
a) Long Int
b) Unsigned Long
c) Int
d) Unsigned Int
View Answer

Answer: c
Explanation: By definition.

12. What will be the output of the following C# code?

  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
View Answer

Answer: c
Explanation: The two data type ‘float’ and ‘long’ after arithmetic operation completely converted to nearest whole number 23.
Output :

23

Sanfoundry Global Education & Learning Series – C# Programming Language.

To practice all areas of C# language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.