0% found this document useful (0 votes)
49 views6 pages

Assiut University Faculty of Computers & Information 3th Level

The document contains 29 multiple choice questions about C# programming concepts. The questions cover topics like data types, variables, operators, control structures, arrays, methods and more. The questions test understanding of basic syntax, program flow and logic in C#.

Uploaded by

Marwan Ramoun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views6 pages

Assiut University Faculty of Computers & Information 3th Level

The document contains 29 multiple choice questions about C# programming concepts. The questions cover topics like data types, variables, operators, control structures, arrays, methods and more. The questions test understanding of basic syntax, program flow and logic in C#.

Uploaded by

Marwan Ramoun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Assiut University Faculty of Computers & Information

3th Level ‫البرمجه المرئيه‬ Visual Programming (CS341)


1. Is C# case sensitive when dealing with identifiers?
A Yes B No
C machine dependent D none of the mentioned
2. In a C# program, a control structure:
A Directs the order of execution of the statements in B Dictates what happens before the program starts
the program and after it terminates
C Defines program-specific data structures D Manages the input and output of control characters
3. What signifies the end of a statement block in C#?
A A line that is indented less than the previous line B }
C A comment D end
4. In C#, a variable may be assigned a value of one type, and then later assigned a value of a
different type:
A true B false
5. What is the value of the expression 1 + 2 ^3 * 4?
A 4097 B 108
C 36 D 33
6. What is the output of the following program?
i=1
while (True){
    if(i%3 == 0)
        break;
    console.writeline(i);
    i + = 1; }
A No Output B Error!
7. The C# interpreter takes the code that you write and converts it to the language that the
computer’s hardware understands. Is this statement True or False?
A True B False
8. Suppose you have the following variables defined:
a = 100
b = 50
Write a C# if/else statement to assign variable m to the smaller of a and b.
A if (a < b) B if (a < b)
a = m; m = a;
else else:
b = m; m = b;
9. In C#, a variable must be declared before it is assigned a value:
A true B false
10. Which is the special symbol used in C# to add comments?
A $ B  //
C  # D //*.... *//
11. In C#, strings are…
A immutable B char arrays
C changeable D str objects

1
12. Which of the following mathematical operators can be used to concatenate strings:
A / B *
C + D -
13. In the C# statement x = a + 5 - b:
a and b are ________
a + 5 - b is ________
A terms, a group B operators, a statement
C operands, an expression D operands, an equation
14. Write the output of the following program:
static void Main (){
unsigned int i = 10;
while (i-- >= 0)
cout << i << endl;
system("pause");
return 0;
}
A 10 9 8 7 6 5 4 3 2 1 0 B infinte loop
15. Write the output of the following program:
static void Main(string[] args){
int a, b, c;
for (a = 0; a < 1; a++)
for (b = 0; b <3; b++)
for (c = 0; c <3; c++)
if (a != b && a != c && b != c) Console.WriteLine ("{0}{1}{2}",a , b , c);
}
A 012 B 012021
021
16. Write the output of the following program:
static void Main (){ int x=7,y=8;
Console.WriteLine((x & y));
if((x + y) == (x | y))
Console.WriteLine("NotOK");
else
Console.WriteLine("OK");return 0;}
A 0 B 0
NotOk OK
17. Write the output of the following program:
static void Main (){int a = 12, b = 12, c = 1;
c = (a - b)>0 ? 10 : 12;
Console.WriteLine("The value of c is: {0}",c);}
A The value of c is: 10 B The value of c is: 12
18. Write the output of the following program:
static void Main (){
int a = 5, b = 6, c = 7;
if (a > b)
if (b < c)
c = a;
else

2
c = b;
Console.WriteLine("c= {0}",c); }
A C=7 B C=6
19. Write the output of the following program:
static void Main () {
int number = 1;
while (number <= 3) {
Console.WriteLine("{0} squared is {1}", number, SQR((++number)));
}}
static int SQR(int x) { return (x) * (x); }
A 2 squared is 4 B 1 squared is 4
3 squared is 9 2 squared is 9
4 squared is 16 3 squared is 16
20. Write the output of the following program:
static void Main () {
int number = 1;
while (number <= 3) {
Console.WriteLine("{0} squared is {1}", number, SQR((number++)));
}}
static int SQR(int x) { return (x) * (x); }
A 1 squared is 1 B 0 squared is 1
2 squared is 4 1 squared is 4
3 squared is 9 2 squared is 9
21. Write the output of the following program:
static void Main(string[] args) {
int[] arr = new int[10];
arrayMethod(ref arr);
Console.WriteLine(arr.Length);
}
static void arrayMethod(ref int[] a){
int[] b = new int[5];
a = b;
}
A 5 B 10
22. Write the output of the following program:
static void Main(string[] args) {
char[] asd = { 'A', 'B', 'C' };
string txt = "";
for (int a = 0; a < 3; a++)
for (int b = 0; b < 3; b++)
for (int c = 0; c < 3; c++)
if (a != b && a != c && b != c)
txt += asd[a].ToString() +asd[b].ToString() + asd[c].ToString();
Console.WriteLine(txt);
}
A ABCACBBACBCACBACAB B ABCACBBACBCACABCBA
23. Write the output of the following program:
static void Main(string[] args) {
int[] arr = new int[] { 1, 2, 3, 4, 5 };
Console.WriteLine(fun1(ref arr));

3
}
static string fun1(ref int[] array) {
for (int i = 0; i < array.Length; i = i + 2)
array[i] = array[i] + 10;
return (string.Join(",", array));
}
A 11,2,13,4,15 B 11,2,12,4,16
24. Write the output of the following program:
static void Main(string[] args){
int[] i = new int[0];
Console.WriteLine(i[0]);
}
A 0 B Exception
25. Write the output of the following program:
static void Main(string[] args) {
var stringValue = "Hello World!";
var stringValue2 = stringValue;
stringValue = "Hello Egypt!";
Console.WriteLine(stringValue2);
var array = new[] { 1, 2, 3, 4 };
var array2 = array;
array[0] = 99;
Console.WriteLine(array2[0]);
}
A Hello World! B Hello Egypt!
99 99
26. Write the output of the following program:
static int div(int a, int b = 5){
return (a + b);
}
static void Main(string[] args){
Console.WriteLine(div(120));
Console.WriteLine(div(120, 4));
}
A 124 B 125
125 124
27. Write the output of the following program:
static void Main(string[] args){
var v = "Hello World!";
v = 10;
System.Console.WriteLine(v);
}
A Compile error B Run time error
28. Write the output of the following program:
static void Main(string[] args){
int[] Asd = { 1, 8, 3, 6, 2, 5, 9, 3, 0, 2 };
Value(Asd, ref Asd[0]);
Console.WriteLine("The return value is {0}", Asd[0]);
}
static void Value(int[] asd, ref int Val){

4
for (int i = 1; i < asd.Length; i++) {
if (asd[i] > Val)
Val = asd[i];
}

A The return value is 9 B The return value is 1


29. Write the output of the following program:
static void Main(string[] args){
int[] S = { 1, 2, 3, 4 };
int[,] R = { { 1, 2 }, { 3, 4 } };
int[][] J = { new int[] { 1, 2 }, new int[] { 3, 4 } };
Console.WriteLine("{0} {1} {2}", S.Length, R.Length, J.Length);
}
A 442 B 444
30. Write the output of the following program:
static void Main(string[] args){
classA a = new classC();
Console.WriteLine(a.Print());
}
public class classA{
public virtual string Print(){
return "classA";
}}
public class classB : classA {
public override string Print()
{
return "classB";
}}
public class classC : classB{
public new string Print(){
return "ClassC";
}}
A ClassC B ClassB
31. Which of the following statements are correct for the given code snippet:
shape obj;
obj = new shape();
A Creates an object of class shape. B To create an object of type shape on the heap or stack
depending on its size.
C Create a reference obj of the class shape and an D Create an object of type shape on the stack.
object of type shape on the heap.

32. Write the output of the following program when the input is 5:
static void Main(string[] args){
int N = int.Parse(Console.ReadLine());
int first = 0, second = 1, next;
for (int i = 0; i < N; i++){
if (i <= 1)
next = i;
else{
next = first + second;

5
first = second;
second = next;
}
Console.Write("{0} ", next);
}
}
A 11235 B 01123
33. Write the output of the following program when the input is 5:
static void Main(string[] args){
int n = int.Parse(Console.ReadLine());
for (int i = 1; i <= n; i++){
for (int j = 1; j <= i; j++){
Console.Write("{0}{1}", j, " ");
}
Console.WriteLine();
}
}
A 1 B 1
1 2 1 3
1 2 3 1 3 5
1 2 3 4 1 3 5 7
1 2 3 4 5 1 3 5 7 9

34. Write the output of the following program when the input is 5111:
static void Main(string[] args){
int N = int.Parse(Console.ReadLine());
int sum = 0;
while (N != 0){
sum += N % 10;
N = N / 10;
}
Console.WriteLine(sum);
}
A 88 B 8
35. Write the output of the following program:
static void Main(string[] args)
{
Console.Write ("*\n**\n***\n****\n*****\n");
}
A * B *****
** ****
*** ***
**** **
***** *

Good Luck , Prof. Yousef Bassyouni Mahdy

You might also like