T4Tutorials .PK

VU Past Papers CS201- Midterm Solved Questions on C/C++ Program Structure and Output

Q#1: What is the role of the preprocessor in the C++ program execution process?
Answer: The preprocessor processes the program before compilation. It handles directives such as #include and #define and includes necessary header files (like iostream) so the compiler can understand required functions and instructions.


Q#2: Explain the significance of the “main” function in a C program.
Answer: The main function is the starting point of every C program. When a program runs, execution begins from the main() function. Without it, the program cannot be compiled or executed.


Q#3: Why is the semicolon (;) at the end of a C statement important, and what happens if it is missing?
Answer: The semicolon (;) marks the end of a statement in C/C++. If it is missing, the compiler generates a syntax error during compilation. A single semicolon alone represents a null statement that performs no action.


Q#4: How does the “cout” stream work in C++, and what does the line cout << “Welcome to Virtual University of Pakistan”; do?
Answer: cout is used to display output on the screen in C++. The << operator sends data to the output stream. The statement
cout << “Welcome to Virtual University of Pakistan”;
prints the message Welcome to Virtual University of Pakistan on the screen.

Exit mobile version