0% found this document useful (0 votes)
17 views23 pages

Quizzes

The document contains a series of programming questions and answers related to C# and general programming concepts. It covers topics such as function outputs, variable scopes, control structures, and language characteristics. The questions test knowledge on syntax, logic, and the behavior of code snippets.

Uploaded by

youssefnasef20
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)
17 views23 pages

Quizzes

The document contains a series of programming questions and answers related to C# and general programming concepts. It covers topics such as function outputs, variable scopes, control structures, and language characteristics. The questions test knowledge on syntax, logic, and the behavior of code snippets.

Uploaded by

youssefnasef20
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/ 23

Consider the following function:

Static double Function1(double x, int n)


{
double result=0;
for(int i = 1; i <= n; i++)
result *= x;
return result;
}
What will be the output of the function if it is called using the parameters: 3, -2
• 0
• 1
• 0.111111
• run-time error occurs

High-Level language is named as High-Level because


• It’s highly dependent on the machine.
• It’s independent on the machine.
• It has a high performance.
What will be the output of the following code snippet:
int const c = 2;
switch (c)
{
case c:
Console.WriteLine("A");
break;
case c * 1:
Console.WriteLine("B");
break;
case c - 2:
Console.WriteLine("C");
break;
default:
Console.WriteLine("D");
}
• A
• B
• D
• Compilation Error
What will be the output of the following C# code?
static void Main(string[] args)
{
int a, b, c, x;
a = 90;
b = 15;
c = 3;
x = ++a - b / 3 + c * 2 - 1;
Console.WriteLine(x);
Console.ReadLine();
}

• 92
• 89
• 90
• 91

Considering programming and programs, a library is


• Used by the the program user.
• Used by the program developer.
• A special type of applications.
• All the given.

If a function returns no value, the return type must be declared as void


• true
• false
Consider the following code:
using System;
namespace MyConsole
{
class Program
{
static void Main(string[] args)
{
int number=1;
while (number != 0)
{
Console.WriteLine("Enter a number to canculate its square (0 to quit): ");
number = int.Parse(Console.ReadLine());
Console.WriteLine("The square of " + number + " is " + number * number);
}
}
}
}
How many time the loop body is executed?
• 0
• 1
• Infinite
• As the user needs
What is the duration of a variable defined indside a method?
• Program execution duration.
• Method execution duration.
• class execution duration.
• None of the given.

Which of the following statements is correct about functions in C#?


• C# allows a function to have arguments with default values.
• It is possible to define a local variable in the function body that has the same name
as a parameter.
• A function can be defined without specifying a return type.
• A function can be defined with many return types.

Which of the following is not a comparison operator in C# language?


• >
• <=
• =
• ==

The Contents of a memory location is changed When The Program….


• Read from it
• Write into it
• All the given

A Computer program can be designed and implemented to:


• Manage a small pharmacy
• Manage a Learning organization
• Control a textile machine
• Any of the given
What will be the output of the following C# code?
static void Main(string[] args)
{
string s1 = "Delhi";
string s2;
s2 = s1.Insert (6, "Jaipur");
Console.WriteLine(s2);
}
• DelhJaipuri
• Delhi Jaipur
• Delhi
• DelhiJaipur

What is the output of the following C# TLS ?


int b = 12;
float a = 16.4f , c = a * (b + a) / (a - b);
Console.WriteLine("result is :" +c);

• 106
• 104.789
• 105.8546
• 103.45
What is the output of the following C# code?
int a,b ;
for (a=2 ; a>=0 ; a- )
{
for (b=0 ; b<= 2 ; b++ )
{
if (a==b)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("0");
}
}
Console.WriteLine("\n");
}
• 100
010
001
• 010
100
001
• 001
010
100
• 100
001
010
What will be the output of the following C# code?
static void Main(string[] args)
{
int a,b;
int c=10;
int d=12;
int e=5;
int f=6;
a = c*(d+e)/f+d;
Console.WriteLine(a);
b = c*(d+e/f+d);
Console.WriteLine(b);
if (a<b)
{
Console.WriteLine("Parentheses Changes Values");
}
else if (a>b)
{
Console.WriteLine("they have same value");
}
}
• They have same value
• Parentheses Changes Values
• Since both have equal values , no conclusion
• None of the mentioned
Consider the following method:
public static void Divide(double first , double second)
{
Console.WriteLine("The division of {0} by {1} is {2}", first , second , first/ second);
}
What will be the output when called the method from another method defined in the
same static class as : Divide(5,2);
• This will give Compiler error due to incompatible parameter types
• The output is: The division of 5 by 2 is 2 is 2
• The output is: The division of 5 by 2 is 2 is 2.5
• The output is: The division of 5,2,2.5

High-Level language is named as High-Level because


• It's highly dependent on the machine
• It's independent on the machine
• It has a high performance
Consider the following:
static void Main(string[] args)
{
int a=5;
int s=0 , c=0 ;
Mul(a , ref s , ref c );
Console.WriteLine(s + "t " + c);
}
static void Mul (int x , ref int ss , ref int cc )
{
ss = x*x ;
cc = x*x*x ;
}
What is the output of the main function
• 125t 25
• 25t 125
• Compile time error
• 0t 0
Consider the following method:
public static void Divide(double first , double second)
{
Console.WriteLine("The division of {0} by {1} is {2}", first , second , first/ second);
}
What will be the output when calling the method from another method defined in the
same static class as : Divide(5,0);
• This will give Compiler error due to incompatible parameter types
• runtime error
• The output is: The division of 5 by 2 is 2 is 2
• The output is: The division of 5,0,infinity

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


int I , j=1 , k ;
for (i=0 ; i<3 ; i++)
{
k = j++ - ++j ;
Console.WriteLine(k + " ");
}
• -4 -3 -2
• -6 -4 -1
• -2 -2 -2
• -4 -4 -4
A computer program can be designed and implemented to:
• Manage a small grocery
• Manage a bank
• Serve a web site such as YouTube
• Any of the given

The syntax error is:

• detected by the compiler


• prevents the compiler to generate the machine code
• violating the language grammar and rules
• all the given

C sharp function can have ….. parameter(s)


• Many
• One
• Zero , One , or many
• Zero or one
What will be the output of the following C# code?
static void Main(string[] args)
{
const int a = 5 ;
const int b = 6 ;
for(int i =1 ; i<=5 ; i++)
{
a = a*i ;
b=b*i;
}
Console.WriteLine(a);
Console.WriteLine(b);
Console.ReadLine();
}
• 600 , 720
• Compile time error
• 25 , 30
• 5,6

Correct order of priorities are:

• '/' > '%' > '*' > '+'


• '/' > '*' > '%' > '+'
• '*' > '/' > '%' > '+'
• '%' > '*'> '/' > '+'
Computers execute programs Written in…
• Assembly language
• High-level language
• Machine language
• All the given

The correct way of incrementing the operators are :


• ++ a ++
• b ++ 1
• c += 1
• d =+1

in C# program, the function main is …..


• The only method executed
• The first method executed
• The last method executed
Consider the following:
static void Main(string[] args)
{
int a=5;
int s=0 , c=0 ;
Mul(a , ref s , ref c );
}
static void Mul (int x , ref int ss , ref int cc )
{
ss = x*x ;
cc = x*x*x ;
}
• By value
• By reference
• By value and by reference
• None of the above

A function can return more than one value ?

• true
• false
Consider the following function:
static double function1(double x , int n)
{
double result=0;
for(int i=1 ; i<=n ; i++)
result *= x;
return result;
}
What will be the output of the function if it is called using the parameters : 3,0
• Compiler error occurs
• 1
• 0
• run-time error occurs

What is the function of last statement in the main function : Console.ReadLine(); ?

• Data input
• Adding delay
• Waiting until the user can view the program reults
What will be the output of the following C# code?
static void Main(string[] args)
{
char c = 'g';
string s = c.ToString();
string s1 = "I am a human being" + c;
Console.WriteLine(s1);
Console.ReadLine();
}
• I am a human bein c
• I am a human beingg
• I am a human being c
• I am a human bein

Computer memory is used to…

• Store data needed for the programs


• Store the program
• Store data and programs
What will be the output of the following C# code?
static void Main(string[] args)
{
int m=10 , n=5 , p=20;
bool b1 = m*p/n <= p*n/m;
int I = p – 2 * m;
bool b2 = I == 0 ;
int z = Convert.Tolnt32(b2);
int k = Convert.Tolnt32(b1);
Console.WriteLine(k);
Console.WriteLine(z);
}
• 01
• 00
• 10
• 11

What is the output of the following C# TLS ?


int a=90 , b=15 , c=3 , x=a-b/3+c*2-1 ;
Console.WriteLine(x);
• 92
• 89
• 90
• 88
Consider the following Main function in C# program:
static void Main(string[] args)
{
int countersRange =10 ;
for( int i=0 ; j= countersRange ; i<= countersRange && j>=0 ; i++ ; j-- )
{
Console.WriteLine(“{0,-20:d}{1,-20:d}” ,i ,j);
}
}
if the “-“ before each 20 is removed, what is printed in the first line?

• 0 followed by 19 spaces then 10


• 0 followed by 20 spaces then 10
• 19 spaces then 0 then 18 spaces then 10
• {0,20:d}{1,20:d} 0 10
What will be the output of the following C# code?

static void Main(string[] args)

int a, b, c, x;

a= 80;

b = 15;

c = 2;

x = a –(b/3) + (a%c);

Console.WriteLine(x);

Console.ReadLine();

• 78
• -84
• 80
• 75

Computer execute programs Writen in…


• Assembly language
• High-level language
• Machine language
• All the given

A debugger is used in:


• Detecting syntax errors
• Detecting logical error
• The two above items
• None of the above items
What will be the output of the following C# code?
int i = 1 , j=1 ;
While (++I <= 10)
{
j++;
}
Console.WriteLine(i+" " +j);

• 12 11
• 10 11
• 11 12
• 11 10

for a source file that contains 100 lines of code of which the line numbered 50 contains
a syntax error, the compiler:
• compiles the first 49 line and scops
• compiles the all lines sxcept the line numbered 50
• Does not compile the source file.,it only announces the errors
• Hangs up and stop working
What will be the output of the following C# code?
static void Main(string[] args)
{
const int a = 5 ;
const int b = 6 ;
for (int i =1 ; i<=5 ; i++)
{
a= a*i ;
b= b*i ;
}
Console.WriteLine(a);
Console.WriteLine(b);
Console.ReadLine();
}

• 600, 720
• Compile time error
• 25, 30
• 5, 6

Given:
int x=2 ;
x*=2;
int y = x++ +2 ;
The value of y is:
• 4
• 6
• 8
• 9
Java programming language is:
• a high-level language
• used to write cross-platform applications
• used to write applications that target a virtual machine
• all the given

The logical programming error is:


• Detected by the compiler
• Prevents the compiler to generate the machine code
• Violating for the language grammar and rules
• None of the given

A high-level programming language is described as high-level because:

• It is used only for complex programs


• It is difficult to read or write in it for humans
• It is near to machine language
• It is near to the human language

You might also like