1️⃣1️⃣ What is the difference between "for", "while", and "do-while" loops?
Answer:
All three loops are used to execute a block of code repeatedly, but they differ in how and when the condition is checked.
• for loop: Best when the number of iterations is known.
• while loop: Best when the number of iterations is unknown and depends on a condition.
• do-while loop: Executes the code at least once because the condition is checked after the loop body.
1️⃣2️⃣ What are Functions?
Answer:
A function is a reusable block of code that performs a specific task. Functions improve code readability, reusability, and maintainability by avoiding code duplication.
Benefits:
• Code reusability
• Better organization
• Easier debugging
• Improved maintainability
1️⃣3️⃣ What is the difference between Parameters and Arguments?
Answer:
• Parameters are variables declared in a function definition.
• Arguments are the actual values passed to the function when it is called.
Example:
function add(a, b) { // a and b are parameters
return a + b;
}
add(5, 10); // 5 and 10 are arguments
1️⃣4️⃣ What is Recursion?
Answer:
Recursion is a programming technique in which a function calls itself to solve a problem by breaking it into smaller subproblems. Every recursive function should have a base case to stop infinite recursion.
Example: Calculating factorial or Fibonacci numbers.
1️⃣5️⃣ What is Scope?
Answer:
Scope defines where a variable can be accessed in a program.
Types of Scope:
• Local Scope
• Global Scope
• Block Scope (in many modern programming languages)
• Function Scope
Variables can only be accessed within their defined scope.
1️⃣6️⃣ What are Global and Local Variables?
Answer:
• Global Variable: Declared outside functions and can be accessed throughout the program.
• Local Variable: Declared inside a function or block and can only be accessed within that function or block.
Generally, local variables are preferred because they reduce unintended side effects.
1️⃣7️⃣ What are Arrays?
Answer:
An array is a data structure that stores multiple elements of the same data type in contiguous memory locations. Each element is accessed using an index.
Example:
int numbers[] = {10, 20, 30, 40};
1️⃣8️⃣ What are Strings?
Answer:
A string is a sequence of characters used to represent text. Depending on the programming language, strings may be immutable (e.g., Java, Python) or mutable using specific classes.
Example:
"Hello, World!"
1️⃣9️⃣ What is Debugging?
Answer:
Debugging is the process of finding, analyzing, and fixing errors (bugs) in a program to ensure it works correctly.
Common Debugging Techniques:
• Using breakpoints
• Printing variable values
• Reading error messages
• Using debugging tools in an IDE
• Writing unit tests
2️⃣0️⃣ What are Syntax, Logical, and Runtime Errors?
Answer:
• Syntax Error: Occurs when the code violates the programming language's grammar rules. The program won't compile or run.
• Logical Error: The program runs successfully but produces incorrect results because of faulty logic.
• Runtime Error: Occurs while the program is executing, such as dividing by zero or accessing invalid memory.
Understanding these error types helps developers identify and fix problems more efficiently.
Double Tap ❤️ For Part-3