CS201 Solved Midterm Papers in One File (MCQs Mega File)

CS201 Midterm Solved Papers

Here is CS201 Solved Midterm Papers in One File (CS201 Solved MCQs Mega File) which will be helpful in preparation of Introduction to Programming midterm papers.Wish you best luck!

 

Question No: 1 ( Marks: 1 ) – Please choose one
What is the output of the following statement?
int i = 2.5; do { cout i * 2; } while (i > 3 && i < 10);
(a) 510
(b) 5
(c) 48
(d) error

Question No: 2 ( Marks: 1 ) – Please choose one
Searching is easier when an array is already sorted
(a) True
(b) False
Question No: 3 ( Marks: 1 ) – Please choose one
If an array has 100 elements, what is allowable range of subscripts?
(a) 0 – 99
(b) 1 – 99
(c) 0 – 100
(d) 1 – 100

Question No: 4 ( Marks: 1 ) – Please choose one
What will be the correct syntax to initialize all elements of two-dimensional array to
value 0?
(a) int arr[2][3] = {0,0} ;
(b) int arr[2][3] = {{0},{0}} ;
(c) int arr[2][3] = {0},{0} ;
(d) int arr[2][3] = {0} ;

Question No: 5 ( Marks: 1 ) – Please choose one
Which of the following function returns the size of a string variable?
(a) strlength()
(b) stringlen()
(c) strlen()
(d) strLength()

Question No: 6 ( Marks: 1 ) – Please choose one
Computer can understand only machine language code.
(c) True
(d) False

Question No: 7 ( Marks: 1 ) – Please choose one
What does 5 ^ 6 , evaluate to in decimal where ‘^’ is Exclusive OR operator?
(a) True
(b) False
Detail:- It mean
5 = 0101
6 = 0110
5 ^ 6 = 0011
If both input is same then the output is 0 and if different then output is 1

Question No: 8 ( Marks: 1 ) – Please choose one
Which of the following header file include string conversion functions?
(a) string.h
(b) stdlib.h
(c) ctype.h
(d) sconvert.h

Question No: 9 ( Marks: 1 )
What is meant by C++ statement: const int *ptr = &x;
Solution:-
ptr is a pointer to data of type const int type. And to assign the address of x to
pointer ptr

Question No: 10 ( Marks: 2 )
What is a truth Table?
Solution:-
We know the concept of truth table. The truth tables are very important. These are still a tool available for analyzing logical expressions. We will read logic design in future, which is actually to do with chips and gate. We find it difficult to evaluate a complicated logical expression. Sometimes the logic becomes extremely complicated so that even
writing it as a simple syntax statement in any language.

Question No: 11 ( Marks: 5 )
What are similarities and differences between Structures and Unions?
In structures, we have different data members and all of these have their own memory space. In union, the memory location is same while the first data member is one name for that memory location. However, the 2nd data member is another name for the same location and so on. Consider the above union (i.e. intOrChar) that contains an integer and a character as data members. What will be the size of this union? The answer is the very simple. The union will be allocated the memory equal to that of the largest size data member. If the int occupies four bytes on our system and char occupies one byte, the union intOrChar will occupy four bytes.

Question No: 12 ( Marks: 1 ) – Please choose one
The function of cin is
(a) To display message
(b) To read data from keyboard
(c) To display output on the screen
(d) To send data to printer

Question No:13 ( Marks: 1 ) – Please choose one
In C/C++ language the header file which is used to perform useful task and manipulation
of character data is
(a) cplext.h
(b) ctype.h
(c) stdio.h
(d) delay.h

Question No: 14 ( Marks: 1 ) – Please choose one
Each pass through a loop is called a/an
(a) enumeration
(b) Iteration
(c) culmination
(d) pass through

Question No:15 ( Marks: 1 ) – Please choose one
What is the correct syntax to declare an array of size 10 of int data type?
(a) int [10] name ;
(b) name[10] int ;
(c) int name[10] ;

Question No: 16 ( Marks: 1 ) – Please choose one
What will be the correct syntax to initialize all elements of two-dimensional array to
value 0?
(a) int arr[2][3] = {0,0} ;
(b) int arr[2][3] = {{0},{0}} ;
(c) int arr[2][3] = {0},{0} ;
(d) int arr[2][3] = {0} ;

Question No: 17 ( Marks: 1 ) – Please choose one
Which of the following operator is used to access the value of variable pointed to by a
pointer?
(a) * operator
(b) -> operator
(c) && operator
(d) & operator

Question No: 18 ( Marks: 1 ) – Please choose one
Analysis is the ————– step in designing a program
(a) Last
(b) Middle
(c) Post Design
(d) First

Question No: 19 ( Marks: 1 ) – Please choose one
Paying attention to detail in designing a program is _________
(a) Time consuming
(b) Redundant
(c) Necessary
(d) Somewhat Good

Question No: 20 ( Marks: 1 )
Which programming tool is helpful in tracing the logical errors?
Debugger tool is helpful in tracing the logical errors.

Question No: 21 ( Marks: 1 )
Give the syntax of opening file ‘myFile.txt’ with ‘app’ mode using ofstream variable
‘out’.
ofstream outfile;
outfile.open (“myFile.txt “); // Open the file

Question No: 22 ( Marks: 2 )
What is the difference between switch statement and if statement.
In switch statement only one variable can be tested on various condition but using if we
can tested multi variables in single statement.

Q.23 The while loop becomes infinite,
(a) When the condition is always false
(b) . When the condition is less than zero
(c) When the condition is always true
(d) When the condition contains a logical operator
Q.24: Which of the following function(s) is/are included in stdlib.h header file?
(a) double atof(const char *nptr)
(b) int atoi(const char *nptr)
(c) char *strcpy ( char *s1, const char *s2)
(d) 1 and 2 only
Q.25: If we want to store a string “abc” in an array str then the size of this array must be
at least,
(a) 2
(b) 3
(c) 4
(d) 5
Q.26: No executable code will be generated if error is found during translation of the program using interpreter.
(a) True
(b) False

Q27: Word processor is
(a) Operating system
(b) Application software
(c) Device driver
(d) Utility software

Q.28: Which of the following is correct way to initialize a variable x of int type with value 10?
(a) int x ; x = 10 ;
(b) int x = 10 ;
(c) int x, x = 10;
(d) x = 10 ;

Q.29: If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?
(a) parentheses ( )
(b) braces { }
(c) brackets [ ]
(d) arrows < >

Q30: Name of an array is a constant pointer.
(a) True
(b) False

Q.31: Loader loads the executable code from hard disk to main memory.
(a) True
(b) False
Q.32: Which of the following is used with bit manipulation?
(a) Signed integer
(b) Un-signed integer
(c) Signed double
(d) Un-signed double
Q.33 : Which of the follwoing values C++ use to represent true and false?
(a) 1 and 0
(b) 1 and -1
(c) 11 and 00
(d) Any numerical value

Q.34: Write a recursive function that takes character array and starting subscript as arguments. In each recursive call, the function should display the string from subscript to the end of string. The starting subscript in first call should be 0. In each successive call, the subscript should increse by one and function should print the array from subscript to the end of string. The function should stop processing and return when null character encounters.
Suppose the char string passed to the function is, “SampleString”, then the function will print output as follows,
SampleString
ampleString
mpleString
pleString
so on…

Question No: 35 ( Marks: 1 ) – Please choose one
A precise sequence of steps to solve a problem is called
 Statement
 Program
 Utility
 Routine
Question No: 36 ( Marks: 1 ) – Please choose one
The Compiler of C language is written in
 Java Language
 UNIX
 FORTRON Language
 C Language
Question No: 37 ( Marks: 1 ) – Please choose one
Initialization of variable at the time of definition is,
 Must
 Necessary
 Good Programming
 None of the given options
Question No: 38 ( Marks: 1 ) – Please choose one
In if structure the block of statements is executed only,
 When the condition is false
 When it contain arithmetic operators
 When it contain logical operators
 When the condition is true
Question No: 39 ( Marks: 1 ) – Please choose one
Which of the following function(s) is/are included in stdlib.h header file?
 double atof(const char *nptr)
 int atoi(const char *nptr)
 char *strcpy ( char *s1, const char *s2)
 1 and 2 only
Question No: 40 ( Marks: 1 ) – Please choose one
Dealing with structures and functions passing by reference is the most economical
method
 True
 False

Question No: 41 ( Marks: 1 ) – Please choose one
Preprocessor program perform its function before ______ phase takes place.
 Editing
 Linking
 Compiling
 Loading
Question No: 42 ( Marks: 1 ) – Please choose one
Which of the following can not be a variable name?
 area
 _area
 10area
 area2
Question No: 43 ( Marks: 1 ) – Please choose one
Which looping process is best, when the number of iterations is known?
 for
 while
 do-while
 all looping processes require that the iterations be known

Question No: 44 ( Marks: 1 ) – Please choose one
What’s wrong with this for loop?
for (int k = 2, k <=12, k++)
 the increment should always be ++k
 the variable must always be the letter i when using a for loop
 there should be a semicolon at the end of the statement
 the commas should be semicolons
Question No: 45 ( Marks: 1 ) – Please choose one
For which array, the size of the array should be one more than the number of elements in
an array?
 int
 double
 float
 char

What will be the output of the following segment of C++ code?
int A[5] = {1 , 2, 3, 4};
int i;
for (i=0; i<5; i++)
{
A[i] = 2*A[i];
cout << A[i] << ” “;
}
ANS
2 4 6 8 0

Q46: In C/C++ the string constant is enclosed
(a) In curly braces
(b) In small braces
(c) In single quotes
(d) In double quotes
Q47: In flow chart, the symbol used for decision making is,
a) Rectangle
b) Circle
c) Arrow
d) Diamond

Q48 The operator used to take the address of a variable is,
(a) &&
(b) ++
(c) –
(d) &
Q49: The header file which is used for input and output is
(a) maths.h
(b) string.h
(c) iostream.h
(d) ctype.h
Q50: When we are using command line argument(s), the default argument in C/C++
is/are ____________ .
a) argc
b) argd
c) argv
d) argc and argv
Q51: In C++, Integer calculation occurs in _____ bytes.
a) 1 byte
b) 2 bytes
c) 4 bytes
d) 8 bytes

Q52: In the declaration of two dimensional array,
(a) First index represents row and second represents column
(b) First index represents column and second represents row
(c) Both indexes represent rows
(d) Both indexes represent column
Q53: The address operator (&) can be used with,
a) Statement
b) Expression
c) Variable
d) Constant

Q54: Which of the following data type(s) can operate on modulus operator ‘%’?
a) float, int
b) float, double
c) int
d) char
Q55: What will be the result of the expression z = x % y, if x = 19 and y = 4?
a) 3
b) 4
c) 15
d) 19
Q56: Which character is inserted at the end of string to indicate the end of string?
a) new line
b) tab
c) null
d) carriage return
Q57: What will be the value of i and j in the following code segment?
int i, j ;
int x[5] = {2, 3, 4, 8, 9} ;
int *ptr =&x[2];
i = (*ptr)++ ;
j = *ptr++ ;
a) i = 5, j = 5
b) i = 5, j = 8
c) i = 4, j = 8
d) i = 5, j = 9

Q58: Syntax of union is identical to ______
a) Structure
b) Class
c) Function
d) None of the given options

Q59: Give the general syntax of definition of structure.
ANS
struct Name
{
// body of the structure
};
Q60: Write the General syntax for the definition of a user defined function. (2)
ANS
return data type Function Name (parameter list with data type)
{
// definition body
}
Q61: What will be the output of following code segment? (3)
int x[5] = {2, 4, 5, 7, 1} ;
int *ptr =&x[2];
cout << (*ptr)++ <<” ” ;
cout << *ptr++ ;
ANS
5 6

Q62 : Detect and correct compile time error(s) in the following code.

Hints: The following code pass a value to a function by Reference and print
the value before and after pass. (5)
ANS
int test (int &x)
{
*x = *x + 200;
return x;
}
main()
{
int x = 100;
cout <<” x = ” <<x;
test (*x); // //invalid type of argument uniary
cout<<endl<< ” x = ” <<x;
getch();
return 0;
}

Q63 : Write a C/C++ program which calculates the aggregate of a student.
The aggregate can be calculated by the formula: (10)
Aggregate = (Matrix_marks*2 + Fsc_marks*4) / 24
If the aggregate of a student is less than 150 then the program should display
message
“You can not be admitted to VU” otherwise display the message
“Congratulation! You admitted in VU “
ANS
#include<iostream.h>
#include<conio.h>

main()
{
int m,f;
float a;
m=254;
f=340;
a = ((m*2) + (f*4))/24;
if(a < 150)
{
cout <<“You can not be admitted to VU”;
}
else
{
cout <<“Congratulation! You admitted in VU “;
}
//Aggregate = (Matrix_marks*2 + Fsc_marks*4) / 24
getche();
}

Q64: What is function of cout ?
(a) To send data to printer
(b) To read data from keyboard
(c) To display message
(d) To display output on the screen
Q65: In Flow chart process is represented by
(a) Rectangle
(b) Arrow symbol
(c) Oval
(d) Circle
Q66 : && is ——————– operator.
(a) An arithmetic
(b) Logical
(c) Relational
(d) Unary

Q67: An over Flow condition occurs when we try to assign a value to a variable which is,
(a) Less than its maximum size
(b) Greater than its maximum size
(c) With in its range
(d) Equal to its size
Q68: For dereferencing an array element using pointer, we use the operator
(a) &
(b) *
(c) /
(d) +
Q69: In the declaration of two dimensional array,
(a) First index represents row and second represents column
(b) First index represents column and second represents row
(c) Both indexes represent rows
(d) Both indexes represent column
Q70: Which of the following data type(s) can operate on modulus operator ‘%’?
(a) float, int
(b) float, double
(c) int
(d) char
Q71: Which of the following is the correct way to declare a variable x of integer type?
(a) x int ;
(b) integer x ;
(c) int x;
(d) x integer

Q72 : Which of the following can not be a variable name?
(a) area
(b) _area
(c) 10area
(d) area2
Q73 : Which of the function call is call by value for the following function prototype?
float area (int);
(a) area(&num) ;
(b) area(num) ;
(c) area(int num) ;
(d) area(*num) ;

Q73: What will be the range of numbers generated by function rand () % 9?
(a) 0 to 9
(b) 1 to 9
(c) 0 to 8
(d) 1 to 8
Q74: What will be the correct syntax to declare two-dimensional array of float data type?
(a) float arr{2}{2} ;
(b) float arr[2][2] ;
(c) float arr[2,2] ;
(d) float[2][2] arr ;
Q75: When a function finishes its execution then,
(a) The control return to its Prototype
(b) The control returns to its definition
(c) Control returns to statement following function call
(d) The compiler stop execution of whole program
Q76: Consider the following statements to initialize a two-dimensional array.
i. int arr[2][3] = {4, 8, 9, 2, 1, 6} ;
ii. int arr[3][2] = {4, 8, 9, 2, 1, 6} ;
iii. int arr[][2] = {{4,8},{9, 2},{1, 6}} ;
Which of the following option(s) are correct to initialize a two-dimensional
array with 3 rows and 2 columns?
(a) (ii) only
(b) (iii) only
(c) (ii) and (iii)
(d) (i) and (iii)
Q77: Editors are used to compile the code.
(a) True
(b) False

Q78: Write down the general syntax of switch statement. (22)
ANS
switch ( variable/expression )
{
case constant1 : statementLlist1 ;
case constant2: statementLlist1 ;
default: statementLlist1 ;
}

Q80: What will be the output of following code segment? (3)
int x[5] = {2, 4, 5, 7, 1} ;
int *ptr =&x[2];
cout << (*ptr)++ <<” ” ;
cout << *ptr++ ;
ANS
5 6
Q81 : What is the difference between compiler and interpreter? (5)
ANS
compiler and interpreter are system software but the difference is that the
complier compile the whole program but the interpreter is complied line by
line. Compiler are efficient in performance.

Q82 :Write a recursive function that takes three arguments (an integer array, starting subscript ‘s’ and ending subscript ‘e’ ). In first recursive call, the function should display the array from subscript ‘s’ (s = 0) to ‘e’
(e = size of array). In each successive call, the function should print the array from index s+1 to e. The function should stop processing and return when starting subscript becomes equal to ending subscript. For example, if user enters values for array 2, 3, 4, 5, 6 then the recursive function must display the following output.
2 3 4 5 6
3 4 5 6
4 5 6
5 6
6
ANS
#include<iostream.h>
#include<conio.h>
void recursive(int [],int,int);
void main()
{
int array[5];
for(int i=0;i<5;i++)
{
cout<<“\nEnter the “<<i<<” Index number :”;
cin>>array[i];
}
recursive(array,0,4); //0 is the starting index and 4 is the ending subscript
getche();
}
void recursive(int arr[],int s,int e)
{
if(s!=e+1)
{
for(int i=s;i<=e;i++)
cout<<arr[i]<<“\t”;;
cout<<endl;
s++;
recursive(arr,s,e); //Recursive call
}
}

Q83: What is function of cout ?
(a) To send data to printer
(b) To read data from keyboard
(c) To display message
(d) To display output on the screen
Q84: < , <= , > , >= are called ————————— operators.

(a) Logical
(b) Arithmetic
(c) Relational
(d) Conational
Q85: In while loop the loop counter must be initialized,
(a) With in the loop
(b) Before entering the loop
(c) At the end of the loop
(d) None of the given options
Q86 : Data Size of the file is always _________ the actual size of the file.
(a) Greater than
(b) Equal to
(c) Less than or equal to
(d) None of the above
Q87 : The precedence of * is higher than dot operator (.)operator
(a) True
(b) False

Q88 : Let ptr1 and ptr2 are pointer variables that points to integer data type then which one of the following arithmetic is allowed,
(a) ptr1 + ptr2
(b) ptr1 – ptr2
(c) ptr1 * ptr2
(d) ptr1 / ptr2
Q89 : Word processor is
(a) Operating system
(b) Application software
(c) Device driver
(d) Utility software
Q90 : What will be the range of numbers generated by function rand () % 9?
(a) 0 to 9
(b) 1 to 9
(c) 0 to 8
(d) 1 to 8

Q91 : What will be the correct syntax to assign an array named arr of 5 elements to a pointer ptr?
(a) *ptr = arr ;
(b) ptr = arr ;
(c) *ptr = arr[5] ;
(d) ptr = arr[5] ;
Q92 : What will be the output of the following code segment?
char *x = ”programming” ;
cout << *(x+2) << *(x+3) << *(x+5) << *(x+8) ;
(a) prgm
(b) rorm
(c) ogai
(d) ramg
Q93: There is a pointer variable named ptr of type int then address of which type of variable the ptr will store in it?
(a) variable of type char
(b) variable of type short
(c) variable of type int
(d) variable of type double
Q94 : Flow charts explain the working of a program in pictorial format.
(a) True
(b) False
Q95 : The object _______________may be used both for file input and file output
(a) fstream,
(b) ifstream,
(c) ofstream,
(d) none of the given options

Q96:  Most efficient method of dealing with structure variables is to define the structure globally
(a) True
(b) False
Q97 : If a variable is passed by value to a function and the function makes some changes to that variable then it
(a) does not affect the original variable
(b) affects the original variable
(c) causes syntax error
(d) None of the given options

Q98 : Suppose int multi[5][10]; when we are using **multi , it means,
(a) Single dereferencing
(b) Single referencing
(c) Double referencing
(d) Double dereferencing
Q99 : To access the data members of structure _______ is used.
(a) dot operator (.)
(b) * operator
(c)  operator
(d) None of given.
Q100 : The precedence of * is higher than dot operator (.)operator
(a) True
(b) False

 

CS201 Midterm Solved Papers Mega File (Short Questions)