T4Tutorials .PK

VU Past Papers CS201- Midterm Solved Questions on Operators and Decision Making

Q#1: What is the difference between the assignment operator (=) and the equal to operator (==) in C language?
Answer: The assignment operator = is used to assign a value to a variable, while the equality operator == is used to compare two values in a condition. If = is mistakenly used instead of == in a condition (e.g., if (x = 2)), it assigns the value 2 to x instead of comparing it, which can cause a logical error.


Q#2: Explain the purpose of flow charts in programming and how they aid in program design.
Answer: A flowchart is a graphical representation of a program’s logic using symbols and arrows. It helps programmers understand the sequence of steps in a program, design the program structure, and identify logical errors before writing the actual code.


Q#3: How does the if/else structure work in C programming, and how does it handle different conditions?
Answer: The if/else structure is used for decision making in C. If the condition in the if statement is true, the statements inside the if block are executed. If the condition is false, the statements inside the else block are executed.


Q#4: Explain the usage of logical operators (&& and ||) in C programming with relational operators. Provide an example.
Answer: Logical operators && (AND) and || (OR) are used with relational operators to combine multiple conditions.

Example:
if (age > 18 && height > 6) means both conditions must be true.

Exit mobile version