C# Questions & Answers on Use of Variable Number of Arguements for Freshers

1. The method in which large or variable number of arguments are handled is known as:

a) Value parameters
b) Output parameters
c) Parameter arrays
d) None of the mentioned
Answer: c
2. The modifiers used to define an array of parameters or list of arguments:

a) ref
b) out
c) param
d) var
Answer: c
3. What will be the output for the given set of code ?
  1.  static void Main(string[] args)
  2.  {
  3.      object[] a = {" 1 ", 4.0f, " harsh "};
  4.      fun(a);
  5.      Console.ReadLine();
  6.  }
  7.  static void fun(params object[] b)
  8.  {
  9.      for (int i = 0; i < b.Length - 1; i++)
  10.          Console.WriteLine(b[i] + " ");
  11.  }
a) 1 4.0 harsh
b) 1 4
c) 1 4 hars
d) 1 4 harsh
Answer: d

Explanation: ‘a’ is declared as array of objects which is passed as a parameter to a single method fun() using variable number of parameters.
Output : 1 4 harsh
4. Which of the following statements are correct?

a) C SHARP allows a function to have arguments with default values
b) C SHARP allows a function to have variable number of arguments
c) Params is used to specify the syntax for a function with variable number of arguments
d) Omitting the return value type in method definition results into an exception
Answer: b, c
5. What will be the output of the set of code?
  1. static void Main(string[] args)
  2. {
  3.     int [] a = {1, 2, 3, 4, 5};
  4.     fun(a);
  5.     Console.ReadLine();
  6. }
  7. static void fun(params int[] b )
  8. {
  9.     int[] k = { 3, 4, 7, 8,'\0' };
  10.     for (int i = 0; i < b.Length; i++)
  11.     {
  12.         b[i] = b[i] + k[i] ;
  13.         Console.WriteLine( b[i] + " ");
  14.     }
  15. }
a) Compile time error
b) 3, 4, 7, 8, 5
c) 3, 4, 7, 8, 5, 1, 2, 3, 4, 5
d) 4, 6, 10, 12, 5
Answer: d

Explanation: Passing of array parameters declared in main() and hence adding elements of array passed using param to another array k[] declared in fun() method.
Output : 4, 6, 10, 12, 5
6. What will be the output the of given set of code?
  1.  static void Main(string[] args)
  2.  {
  3.      int [] a = {1, 2, 3, 4, 5};
  4.      fun(a);
  5.      Console.ReadLine();
  6.  }
  7.  static void fun(params int[] b )
  8.  {
  9.      for (int i = 0; i < b.Length; i++)
  10.      {
  11.          b[i] = b[i] * 5 ;
  12.          Console.WriteLine(b[i] + "");
  13.      }
  14.  }
a) 1, 2, 3, 4, 5
b) 5, 10, 15, 20, 25
c) 5, 25, 125, 625, 3125
d) 6, 12, 18, 24, 30
Answer: b
Output : 5, 10, 15, 20, 25.
7. What will be the output of the given set of code?
  1.  static void Main(string[] args)
  2.  {
  3.      int[] a = { 2, 21, 34, 46, 85, 88, 90};
  4.      fun(a);
  5.      Console.WriteLine(a + " ");
  6.      Console.ReadLine();
  7.  }
  8.  static void fun(params int [] b )
  9.  {
  10.      int [] c = { 1, 2, 3, 4, 5, 6, 7};
  11.      int i ;
  12.      for (i = 0 ;i < b.Length ;i++)
  13.      if (b[i] % 2 == 0)
  14.      {
  15.          c[i] = b[i];
  16.      }
  17.      Console.WriteLine("even numbers are:");
  18.      for (i = 0 ;i <= b.Length ;i++)
  19.      {
  20.          Console.WriteLine(c[i]);
  21.      }
  22.  }
a) Compile time error
b) 2, 21, 34, 4, 6, 46, 88, 90
c) 2, 4, 34, 46, 6, 88, 90
d) 2, 34, 46, 88, 90
Answer: d
8. Select the correct declaration of the defining array of parameters:
a) void func(int[] x)
{
}
b) void func(int x)
{
}
c) void func(param int[])
{
}
d) void fun(param int[] x)
{
}
Answer: d
9. What will be the output of the given set of code?
  1.  static void Main(string[] args)
  2.  {
  3.      int[] x = { 80, 82, 65, 72, 83, 67 };
  4.      fun(x);
  5.      Console.ReadLine();
  6.  }
  7.  static void fun(params int [] b )
  8.  {
  9.      int i;
  10.      for (i = 5; i >=0 ; i--)
  11.      {
  12.          Console.WriteLine(Convert.ToChar(b[i]));
  13.      }
  14.  }
a) 67 83 72 65 82 80
b) P R A H S C
c) C S H A R P
d) 80 82 65 72 83 67
Answer: c
10. What will be the output of the given set of code?
  1.  static void Main(string[] args)
  2.  {
  3.      int[] x = {65, 66, 67, 68, 69, 70};
  4.      fun(x);
  5.      Console.ReadLine();
  6.  }
  7.  static void fun(params int[] b )
  8.  {
  9.      int i;
  10.      for (i = 5; i > 0 ; i--)
  11.      {
  12.          b[i] = b[i] + 32;
  13.          Console.WriteLine(Convert.ToChar(b[i]));
  14.      }
  15.  }
a) A, B, C, D, E, F
b) F, E, D, C, B, A
c) f, e, d, c, b
d) b, c, d, e, f
Answer: c

Related

C Programming Multiple Choice Questions and Answers on Bit-fields for Freshers

1. What is the correct syntax to initialize bit-fields in an structure? a) struct temp { unsigned int a : 1; }s; b) struct temp { unsigned int a = 1; }s; c) st...

CSS Multiple Choice Questions & Answers on CSS3 Transitions for UI Elements for Freshers

1. Which of the following selector is used to select and style when you place mouse over it? a) focusb) hoverc) moused) all of the mentioned Answer: b 2. Which of the following method increases o...

Java Multiple Choice Questions & Answers on isAlive(), Join() & Thread Synchronization for Freshers

1. Which of these method can be used to make the main thread to be executed last among all the threads? a) stop()b) sleep()c) join()d) call() Answer: b Explanation: By calling sleep() within main...

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