CS201 Introduction To Programming Solved MCQs For Midterm Exam
This document contains 55 multiple choice questions from the CS201 Introduction to Programming course. The questions cover topics taught in lectures 2-10 including variable types, operators, control flow, functions, and more. Each question is followed by the correct answer choice and the lecture number where the topic was covered.
CS201 Introduction To Programming Solved MCQs For Midterm Exam
This document contains 55 multiple choice questions from the CS201 Introduction to Programming course. The questions cover topics taught in lectures 2-10 including variable types, operators, control flow, functions, and more. Each question is followed by the correct answer choice and the lecture number where the topic was covered.
MCQs For Midterm Exam Preparation CS201 1 - Application Softwares are use to 1. Type letters 2. Control computer hardware 3. Solve end user problems 4. Develop Graphics Correct Choice : 3 From Lecture # 2 2 - Computer can do, 1. More than what we tell it 2. Less then what we tell it 3. Like human being 4. Exactly what we tell it Correct Choice : 4 From Lecture # 2 3 - we can control our program while it is running by using 1. Debugger 2. Linker 3. Loader 4. Editor Correct Choice : 1 From Lecture # 2 4 - _______are part of system software 1. Linker and loaders 2. Opreating System and Linker 3. Drivers 4. None of the Given Correct Choice : 1 From Lecture # 2 5 - The remainder (%) operator is, 1. An arithmetic operator 2. A logical operator 3. A relational operator 4. A division operator Correct Choice : 1 From Lecture # 3 6 - int x = 2 * 3 + 4 * 5; What value will x contain in the sample code above? 1. 22 2. 26 3. 46 4. 50 Correct Choice : 2 From Lecture # 3 7 - What is the correct value to return to the operating system upon the successful completion of a program? 1. -1 2. 1
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing 3. 0 4. Programs do not return a value. Correct Choice : 3 From Lecture # 3 8 - What is the only function all C++ programs must contain? 1. start() 2. system() 3. main() 4. program() Correct Choice : 3 From Lecture # 3 9 - What punctuation is used to signal the beginning and end of code blocks? 1. { } 2. - > and < - 3. BEGIN and END 4. ( and ) Correct Choice : 1 From Lecture # 3 10 - What punctuation ends most lines of C++ code? 1. (dot) 2. (semi-colon) 3. (colon) 4. (single quote) Correct Choice : 2 From Lecture # 3 11 - Which of the following is a correct comment? 1. */ Comments */ 2. ** Comment ** 3. /* Comment */ 4. { Comment } Correct Choice : 3 From Lecture # 3 12 - Which of the following is not a correct variable type? 1. float 2. real 3. int 4. double Correct Choice : 2 From Lecture # 3 13 - Which of the following is the correct operator to compare two variables? 1. := 2. = 3. equal 4. == Correct Choice : 4 From Lecture # 3 14 - Identify the correct statement 1. Programmer can use comments to include short explanations within the source code itself. 2. All lines beginning with two slash signs are considered comments. 3. Comments very important effect on the behavior of the program 4. both
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing Correct Choice : 2 From Lecture # 3 15 - There is a unique function in C++ program by where all C++ programs start their execution 1. Start() 2. Begin() 3. Main() 4. Output() Correct Choice : 3 From Lecture # 3 16 - Every statement in C++ program should end with 1. A full stop (.) 2. A Comma (,) 3. A Semicolon (;} 4. A colon (:) Correct Choice : 3 From Lecture # 3 17 - A variable is/are 1. String that varies during program execution 2. A portion of memory to store a value 3. Those numbers that are frequently required in programs 4. None of these Correct Choice : 3 From Lecture # 3 18 - The value of 2*15/3*7+3*2 is 1. 146 2. 76 3. 8 4. 70 Correct Choice : 2 From Lecture # 3 19 - The size of a double variable is 1. 2 bytes 2. 4 bytes 3. 8 bytes 4. 10 bytes Correct Choice : 3 From Lecture # 3 20 - Which of the following are NOT relational operators ? 1. > 2. < 3. == 4. >= Correct Choice : 3 From Lecture # 3 21 - Which of the following can not be used as identifiers? 1. Letters 2. Digits 3. Underscores 4. Spaces Correct Choice : 4 From Lecture # 4 22 - result of " number = number / 10; " will be equel to The " number = number % 10; "
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing 1. TRUE 2. FALSE 3. 4. Correct Choice : 2 From Lecture # 4 23 - int x,y =10; cout < < x < < endl; The value of the x will be in the above code 1. 0 2. 10 3. unknown Value 4. -1 Correct Choice : 3 From Lecture # 4 24 - In flow chart process is represented by 1. Rectangle 2. Arrow symbol 3. Oval 4. Circle Correct Choice : 1 From Lecture # 5 25 - Which of the following is the boolean operator for logical-and? 1. & 2. && 3. | 4. |& Correct Choice : 2 From Lecture # 5 26 - Evaluate !(1 && !(0 || 1)). 1. TRUE 2. FALSE 3. Unevaluatable 4. None Of The Above Correct Choice : 1 From Lecture # 5 27 - Which one of the following operators is a unary operator? 1. OR ( || ) 2. AND ( && ) 3. XOR ( ^ ) 4. Logical NOT ( ! ) Correct Choice : 4 From Lecture # 5 28 - Which of the following shows the correct syntax for an if statement? 1. if expression 2. if{ expression 3. if( expression) 4. expression if Correct Choice : 3 From Lecture # 5 29 - In if structure the block of statements is executed only, 1. Type letters 2. When it contain arithmetic operators 3. When it contain logical operators
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing 4. When the condition is true Correct Choice : 4 From Lecture # 6 30 - Loader transfers the executable code from main memory to hard disk. 1. TRUE 2. FALSE 3. 4. Correct Choice : 2 From Lecture # 6 31 - What is the final value of x when the code int x; for(x=0; x < 10; x++) {} is run? 1. 10 2. 9 3. 0 4. 8 Correct Choice : 1 From Lecture # 6 32 - When does the code block following while(x< 100) execute? 1. When x is less than one hundred 2. When x is greater than one hundred 3. When x is equal to one hundred 4. While it wishes Correct Choice : 2 From Lecture # 6 33 - Which is not a loop structure? 1. For 2. Do while 3. While 4. Repeat Until Correct Choice : 4 From Lecture # 6 34 - for (int n=10; n >0; n++) { cout < < n < < ", "; } How many Time Loop will run 1. 100 2. Infinite Time 3. 1000 4. 10000000 Correct Choice : 2 From Lecture # 6 35 - When break statement is encountered in switch statement, it 1. Stops the entire program 2. Stops the execution of current statement 3. Exits from switch statement 4. None of the given options Correct Choice : 3 From Lecture # 7 36 - A for loop usually consist of __________ expressions. 1. 1 2. 3 3. 2 4. 4 Correct Choice : 3 From Lecture # 7 37 - How many times is a do while loop guaranteed to loop?
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing 1. 0 2. Variable 3. Infinitely 4. 1 Correct Choice : 4 From Lecture # 7 38 - x = x + 4 ; Is Equal to 1. x += 4 ; 2. x =+ 4 ; 3. x == 4 ; 4. x =! 4 ; Correct Choice : 1 From Lecture # 7 39 - The first expression in a for loop is 1. The test expression. 2. The step value of the loop. 3. The first value of our counter variable. 4. None of the above. Correct Choice : 3 From Lecture # 7 40 - What is the break statement used for ? 1. To quit the program. 2. To quit the current iteration. 3. To stop the current iteration and begin the next iteration. 4. None of the above. Correct Choice : 2 From Lecture # 7 41 - What is the continue statement used for ? 1. To continue to the next line of code. 2. To stop the current iteration and begin the next iteration from the beginning. 3. As an alternative to the else statement. 4. None of the above. Correct Choice : 2 From Lecture # 7 42 - What is the output of the following code? for (int a = 1; a < = 1; a++) cout < < a++; cout < < a; 1. 22 2. 12 3. error 4. 23 Correct Choice : 2 From Lecture # 7 43 - every case statement is follows by? 1. : 2. ; 3. - 4. A newline Correct Choice : 1 From Lecture # 8 44 - What is required to avoid falling through from one case to the next? 1. end; 2. break;
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing 3. Stop; 4. A semicolon. Correct Choice : 2 From Lecture # 8 45 - What keyword covers unhandled possibilities in switch case? 1. all 2. contingency 3. default 4. other Correct Choice : 3 From Lecture # 8 46 - What is the result of the following code? x=0; switch(x) { case 1: cout< < "One"; case 0: cout< < "Zero"; case 2: cout< < "Hello World"; } 1. One 2. Zero 3. Hello World 4. ZeroHello World Correct Choice : 4 From Lecture # 8 47 - Which of the following is true? 1. 1 2. -1 3. 0.1 4. All of the above Correct Choice : 1 From Lecture # 9 48 - Every function in C++ are followed by 1. Parameters 2. Parenthesis 3. Curly braces 4. None of these Correct Choice : 2 From Lecture # 9 49 - Which is not a proper prototype? 1. int funct(char x, char y); 2. double funct(char x) 3. void funct(); 4. char x(); Correct Choice : 2 From Lecture # 9 50 - What is the return type of the function with prototype: " int func(char x, float v, double t); " 1. char 2. int 3. float 4. double Correct Choice : 2 From Lecture # 9 51 - Which of the following is a valid function call (assuming the function exists)? 1. funct; 2. funct x, y; 3. funct();
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing 4. int funct(); Correct Choice : 3 From Lecture # 9 52 - Which of the following is a complete function? 1. int funct(); 2. int funct(int x) {return x=x+1;} 3. void funct(int) {cout&tl; < "Hello"} 4. void funct(x) {cout < < "Hello"} Correct Choice : 2 From Lecture # 9 53 - A function prototypes are useful 1. Because they tell the compiler that a function is declared later. 2. Because they make the program more readable. 3. Because they allow the programmer to see a quick list of functions in the program along with the arguments for each function. 4. All of the above. Correct Choice : 4 From Lecture # 9 54 - A function that calls itself is known as 1. Iterative function 2. Inline function 3. Recursive function 4. main () Correct Choice : 3 From Lecture # 10 55 - A preprocessor directive is identified by _________ symbol 1. # 2. { 3. ( 4. ~ Correct Choice : 1 From Lecture # 10 56 - When a call to function statement is encountered, 1. The control is transfer to its Prototype 2. The control is transfer to its definition 3. The compiler stop execution of whole program 4. The program hangs Correct Choice : 1 From Lecture # 10 57 - The directives for the preprocessors begin with 1. Less than symbol (< ) 2. Ampersand symbol (&) 3. Two Slashes (//) 4. Number Sign (#) Correct Choice : 3 From Lecture # 10 58 - The file iostream includes 1. The declarations of the basic standard input-output library. 2. The streams of includes and outputs of program effect. 3. Both of these 4. None of these Correct Choice : 1 From Lecture # 10
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing 59 - Which of the following is false? 1. Cout represents the standard output stream in c++. 2. Cout is declared in the iostream standard file 3. Cout is declared within the std namespace 4. None of above Correct Choice : 4 From Lecture # 10 60 - Which of the following statement is true about preprocessor directives? 1. These are lines read and processed by the preprocessor 2. They do not produce any code by themselves 3. These must be written on their own line 4. They end with a semicolon Correct Choice : 4 From Lecture # 10 61 - If the statements int j,k; j = 123; k= 234; int* q, * r; r = &j; q=&k; cout< < *q< < ' '< < *r; are executed, what will be displayed? 1. The addresses of q and r 2. The addresses of j and k 3. 132 , 234 4. garbage values Correct Choice : 3 From Lecture # 10 62 - If the statements int j,k; j = 123; k= 234; int* q, * r; cout< < *q< < ' '< < *r; are executed, what will be displayed? 1. The addresses of q and r 2. The addresses of j and k 3. 132 , 234 4. garbage values Correct Choice : 4 From Lecture # 10 63 - Which of the following correctly declares an array? 1. int anarray[10]; 2. int anarray; 3. anarray{10}; 4. array anarray[10]; Correct Choice : 1 From Lecture # 10 64 - Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements? 1. foo[6]; 2. foo[7]; 3. foo(7); 4. foo; Correct Choice : 1 From Lecture # 10 65 - Which of the following gives the memory address of the first element in array foo, an array with 100 elements? 1. foo[0]; 2. foo; 3. &foo; 4. foo[1];
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing Correct Choice : 2 From Lecture # 10 66 - Consider the following statement: int age [ ] = { 0, 2, 1, 3, 4, 5, 6, 7, 8, 9 }; Array Length is 1. 10 2. 11 3. 9 4. 0 Correct Choice : 1 From Lecture # 10 67 - c[ 3 ] = 33; by this Code we are assigning the value to 1. 3rd element 2. 4th element 3. 1st element 4. None of the Given Correct Choice : 2 From Lecture # 10 68 - for (i = 0; i < 10 ; i ++) { b[i] = a[i]; } by given loop we are ____ 1. Deleting the two Arrays 2. Comparing the two Arrays 3. Copying the two arrays 4. Doing Nothing Correct Choice : 3 From Lecture # 10 69 - int z, i ; int a [ 100 ] ; z=5; for ( i =0 ; i < 100 ; i ++ ) { a [ i ] = i ; } for ( i = 0 ; i < 100 ; i ++ ) { if ( z == a [ i ] ) { found = 1 ; break ; } } Loop will be executed for ______ 1. 6 Time 2. 5 Time 3. 4 Time 4. 0 Time Correct Choice : 1 From Lecture # 10 70 - Given that #define sum(a,b) a+b what is the value of: sum(3+1,2); 1. 18 2. 6 page 13 / 22 3. 30 4. 5*6 Correct Choice : 2 From Lecture # 10 71 - int m=0,v=0; for(m=5;m < 8;m++){ v=v+(m++)+(++m); } cout< < v < < endl; out put of the V will be ? 1. 36 2. 11 3. 39 4. 26 Correct Choice : 2 From Lecture # 10 72 - Because of variable scope 1. Variables created in a function cannot be used another function. 2. Variables created in a function can be used in another function. 3. Variables created in a function can only be used in the main function
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing 4. None of the above. Correct Choice : 1 From Lecture # 10 73 - When we are using const keyword with a variable x then initializing it at the time of declaration is 1. Must 2. Optional 3. Not necessary 4. A syntax error Correct Choice : 1 From Lecture # 11 74 - void allocateme(int* p){ p = new int; *p = 2; } int main(){ int i = 1; allocateme(&i); std::cout< < i; return 0; } What is displayed? 1. Outputs '1' 2. Outputs '2' 3. Outputs some rubbish value 4. Will not compile Correct Choice : 1 From Lecture # 11 75 - int numarray[4][4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; What value does numarray [0][3] in the sample code above contain? 1. 3 2. 5 3. 7 4. 4 Correct Choice : 4 From Lecture # 12 76 - If the statements < br >int j,k;< br >j = 123;< br >k= 234;< br >int* q, * r;< br > cout < < *q < < ' ' < < * r ;< br >are executed, what will be displayed? 1. The values of j and k 2. The addresses of q and r 3. The addresses of j and k 4. garbage values Correct Choice : 4 From Lecture # 14 77 - Which one of the following will declare a pointer to an integer at address 0x22ff74 in memory? 1. int *x; *x = 0x22ff74; 2. int *x = &0x22ff74; 3. int *x = *0x22ff74; 4. int *x( &0x22ff740 ); Correct Choice : 1 From Lecture # 14 78 - An array is also called 1. an array variable 2. array declaration 3. struct 4. constant pointer Correct Choice : 4 From Lecture # 14 79 - Which of the following is the proper declaration of a pointer? 1. int x;
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing 2. int &x; 3. ptr x; 4. int *x; Correct Choice : 4 From Lecture # 14 80 - Which of the following gives the memory address of integer variable a (int a;)? 1. &a; 2. *a; 3. address(a); 4. a; Correct Choice : 1 From Lecture # 14 81 - Which of the following is the proper Operator to allocate memory? 1. new 2. malloc 3. create 4. value Correct Choice : 1 From Lecture # 14 82 - Which of the following is the proper keyword to deallocate memory? 1. free 2. delete 3. clear 4. remove Correct Choice : 2 From Lecture # 14 83 - When we are calling function i.e. swap(&x, &y); then it is a call by 1. Reference 2. Value 3. Name 4. Nick Name Correct Choice : 1 From Lecture # 14 84 - Which symbol is used to declare a pointer ? 1. & 2. @ 3. * 4. $ Correct Choice : 3 From Lecture # 14 85 - Which symbol is used to reference a pointer ? 1. * 2. & 3. @ 4. $ Correct Choice : 2 From Lecture # 14 86 - In the given code int y[10]; int *x ; x= y; y is giving 1. Address 2. Whole Array Address 3. Address of the first element of the array 4. Error
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing Correct Choice : 3 From Lecture # 15 87 - Adding to a pointer that points to an array will page 16 / 22 1. Cause an error. 2. Increase the value of the element that the pointer is pointing to. 3. Cause the pointer to point to the next element in the array. 4. None of the above. Correct Choice : 3 From Lecture # 15 88 - Which one of the following operators is a unary operator? 1. OR ( || ) 2. AND ( &&) 3. XOR ( ^ ) 4. Complement operator ( ~ ) Correct Choice : 4 From Lecture # 16 89 - The statement i++; is equivalent to 1. i = i + i; 2. i = i + 1; 3. i = i - 1; 4. i --; Correct Choice : 2 From Lecture # 16 90 - A variable which is defined inside a function is called 1. Automatic variable 2. Global variable 3. Functional variable 4. None of the given option Correct Choice : 3 From Lecture # 16 91 - Which of the following is a two-dimensional array? 1. array anarray[20][20]; 2. int anarray[20][20]; 3. int array[20, 20]; 4. char array[20]; Correct Choice : 2 From Lecture # 16 92 - int twoDArray[2][2] ={0,1,2,3,4,5,6}; the 1st row and 3rd element is; 1. 3 2. 2 3. 4 4. 5 Correct Choice : 2 From Lecture # 16 93 - An array of pointers is the same as_______. 1. pointers to pointers. 2. pointers to Arrray 3. null 4. None of the Given Correct Choice : 1 From Lecture # 16 94 - Pointers may be ________________like any other data type.
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing 1. char 2. arrayed (stored in an array) 3. int 4. float Correct Choice : 2 From Lecture # 16 95 - In C/C++ language when an array is passed to a function then by default its passing Mechanism is, 1. Call by value 2. It depends on type of array 3. Call by Reference 4. It depends on the return type of function. Correct Choice : 3 From Lecture # 17 96 - int isdigit( int c ) Returns true if c is a______ 1. char 2. int 3. digit 4. None of the Given Correct Choice : 3 From Lecture # 17 97 - int isupper( int c ) Returns true if c is a______ 1. uppercase letter 2. lowercase letter 3. int 4. float Correct Choice : 1 From Lecture # 17 98 - double atof( const char *nPtr ) Converts the string nPtr to 1. double. 2. int 3. char 4. float Correct Choice : 1 From Lecture # 17 99 - The basic steps of file handling are: page 18 / 22 1. Open the file, Read and write, Close the file 2. Read, Close the file, Open the file 3. Open the file, Close the file, write 4. Non of the Given Correct Choice : 1 From Lecture # 18 100 - ofstream outFile; char outputFileName[] = "myFileOut.txt"; char ouputText[100] = "Welcome to VU"; outFile.open(outputFileName); at the end of the code 1. file is opened for Writing 2. file is opened for reading 3. file is not opened 4. file is closed Correct Choice : 1 From Lecture # 18 101 - If we open a file stream myfile for reading, what will give us the current position of
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing the file pointer? 1. tellg() 2. tellp() 3. seekg() 4. seekp() Correct Choice : 1 From Lecture # 19 102 - If we open a file stream myfile for reading, what will give us the current position of the file pointer? 1. tellg() 2. seekp() 3. seekg() 4. tellp() Correct Choice : 4 From Lecture # 19 103 - Which of the following classes handlers file input? 1. ofstream 2. ifstream 3. instream 4. inputfile Correct Choice : 2 From Lecture # 19 104 - By writing: aFile. seekg (10L, ios::beg) We are asking to move 10 bytes______ 1. back from the End 2. forward from the begining 3. forward from the Currant Position 4. None of the above. Correct Choice : 2 From Lecture # 19 105- By using seekg () function, we can know the actual___________ 1. data length 2. seek of data 3. data position 4. None of the above. Correct Choice : 1 From Lecture # 19 106- we will call tellg () to give the current position in ________number. This number is the actual data bytes inside the file. 1. int 2. short 3. long 4. double Correct Choice : 3 From Lecture # 19 107 - We can use inputFile.getc () to get a_______________and outputFile.putc () to write a______into a file. 1. character,character 2. int,character 3. character,short 4. Non of the Given Correct Choice : 1 From Lecture # 19
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
CS101 Introduction of computing 108 - ____________will return the number of bytes reserved for a variable or data type. 1. sizeof operator 2. free operator 3. void pointer 4. new operator Correct Choice : 1 From Lecture # 19 109 - To access the members of a structure, which symbol is used ? 1. * 2. - 3. ` 4. . Correct Choice : 4 From Lecture # 20 110 - A member is a 1. Variable in a structure. 2. Structure's datatype. 3. Pointer to a structure. 4. None of the above. Correct Choice : 1 From Lecture # 20 111 - Which of the following is a properly defined struct? 1. struct {int a;} 2. struct a_struct {int a;} 3. struct a_struct int a; 4. struct a_struct {int a;}; Correct Choice : 4 From Lecture # 20 112 - Which properly declares a variable of struct Student? 1. struct student; 2. struct Student; 3. struct st; 4. int Student; Correct Choice: 2 From Lecture # 20 113 - Using structures we can declare: 1. Simple variables, Pointers and Arrays of structure 2. Simple variables 3. Pointers and Arrays of structure 4. Nothing Correct Choice: 1 From Lecture # 20 114 - During compilation compiler looks for the ____________ and process it first 1. source code 2. object code 3. built in functions 4. preprocessor directives Correct Choice : 4 From Lecture # 20 115 - When we write a class template the first line must be: 1. template < class class_type > 2. template < class data_type >
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan