CS201 Midterm Solved Subjective with References by Moaaz
- Type
- Midterm past paper
- Course
- CS201 Introduction to Programming
- Size
- PDF 1.3 MB
- Updated
- 23 Oct 2026
You get 3 free files a day on the website. Add the Chrome extension for 30 a day.
Preview text
Text from pages 1, 2, 3 of 26. Download the file for all 26 pages.
Lectures 1-22 Moaaz Siddiq
Latest subjectives
Spring 2010
Q17. Answer: (2 marks)
- if statement is used when we have to check two conditions while switch is a multi conditional control statement
- SWITCH statement can be executed with all cases if the “break” statement is not used whereas IF statement has to be true to be executed further.
Q18. Why we close a file after use? (2 marks)
Answer: To save our data stored on file. Also this process makes our program fast and reliable. OR You have finished with it. This is particularly important if you are writing to the file. The operating system does not switch on the disk drive to write just a single character to the disk, rather it waits until it has a load to write and then writes the lots in one go.
Q19. A two-dimensional array has 3 rows and 4 columns. Write down the syntax to initialize first element of all three rows of two-dimensional array with value 2. (2 marks)
Answer: int matrix[0][0]=2 int matrix[1][0]=2 int matrix[2][0]=2
Q20. main(){ (3 marks)
int x = 10
*ptr = 5 ;
Answer: Int x=10….No ending semicolon. *ptr=5... Declaring a pointer to constant integer. You cannot use this pointer to change the value being
Q21. Can you use an assignment operator to assign the value of one C-string to another? (3 marks)
Answer: Yes we can assign the one value of C-string to another using assignment operator. We can assign the value of one string to another string through this method. A[0]=B[0] A[1]=B[2] A[3]=B[3] And we can assign the whole string to another C string using Assignment operator by using loops.
Q22. Why binary search algorithm is more efficient than the linear search algorithm? (5 marks)
Answer: (page118) Binary search algorithm is more efficient than liner algorithm because the arrays are sorted in asending or desending order and we use “devide and conqrer” technique. In binary search each iteration reduces the search by the factor of two but in the linear we have the same number of searches as we have the number of elements.e.g,if we have array of 1000 elements the linear search will take 1000 iterations however binary search will take max 10.
Q23. Write down the output of the code given below : (5 marks)
Hint:
Size of char is 1 byte Size of int is 2 byte Size of float is 4 byte
union mytypes_t { char c; int i; float f; } mytypes;
int main(){
mytypes.i = 15; mytypes.i = 15;
system("PAUSE"); return 0;
Q16. In Program commenting the code liberally is (1 marks)
Answer: (page 06) It need to be self-contained and understandable. Comments should be placed liberally. The comments should explain the logic, not the mechanics. Try to avoid fancy programming.
Q17. Which header file must be included while handling files? (1 marks)
Answer: (page 199) Include <fstream.h>
Q18. What is meant by C++ statement: const int *ptr = &x; (1 marks)
Answer: ptr is a pointer to data of type const int type. And to assign the address of x to pointer ptr
Q19. What is a truth Table? (2 marks)
Answer: (page 562) 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. These are used to make a big circuit with the use of minimum chips. These minimization techniques deal with Boolean algebra i.e. logic.
Q20. (1) An array day is declared as: int day[] = {1, 2, 3, 4, 5, 6, 7}; (3 marks)
How many elements does array 'day' has?
Answer: 7 elements
Related CS201 files
All CS201 files →- CS201 Midterm Solved MCQs with References by Moaaz and Asad Midterm PDF 270 KB
- CS201 Midterm Past Papers by Tariq Midterm PDF 60 KB
- CS201 Midterm Solved MCQs by Moaaz and Asad Midterm PDF 277 KB
- CS201 Highlighted Handouts Set 3 Highlighted PDF 3.3 MB
- CS201 Lecture 9 Quiz DOCX 17 KB
- CS201 Final Term Solved File 1 by Team Hadi Final term PDF 1.4 MB
Get more out of VUBuddy, for free
- Unlimited downloads
- The explanation behind every MCQ answer
- Study offline on slow data
- 30 downloads a day instead of 3
- Sign in and buy Pro Semester here
One Pro Semester membership works in both the extension and the app.