CPP Programming Concepts
CPP Programming Concepts
i) Control structure, depending on a certain condition, a certain series of events will be executed.
ii) In the Call by value technique, changes made in the function are local to the function and not
iv) In the do...while loop, the condition is tested after the first iteration.
Control structures determine the flow of program execution based on specified conditions. There are
2. Selection (Branching): Uses if, else, or switch statements to execute specific code based on
conditions.
3. Iteration (Looping): Uses loops like for, while, and do...while to repeat a block of code.
while loop: The condition is evaluated before executing the loop body. If the condition is false
do...while loop: The loop body is executed first, and then the condition is checked. This ensures that
An else-if ladder is a series of conditional statements used when multiple conditions need to be
checked sequentially. If one condition is true, the associated block of code executes, and the rest
are skipped.
Example:
if (num < 0) {
} else if (num == 0) {
} else {
The break statement exits the switch-case construct after executing a particular case, preventing
'fall-through' to subsequent cases. Without it, all statements below the matching case will execute.
An infinite loop is one that continues to execute indefinitely because its termination condition is
The continue statement skips the current iteration and proceeds to the next iteration of the loop. It is
Yes, loops can be nested by placing one loop inside another. For example:
cout << 'i: ' << i << ', j: ' << j << endl;
ix) What is a function? Explain the advantages of using functions in your program.
A function is a block of code designed to perform a specific task, which can be called repeatedly.
Advantages include:
2. Modularity: Helps break down a complex program into smaller, manageable parts.
x) What is the difference between a function prototype, function call, and function definition?
Function Prototype: Declares the function signature, providing information about the return type and
parameters.
a) Recursive Function: A function that calls itself. Useful for problems that can be divided into similar
sub-problems.
b) Default Arguments: Predefined values for parameters that are used if no argument is passed.
c) Function Overloading: The ability to define multiple functions with the same name but different
parameter lists.
d) Pass by Value vs. Pass by Reference: Pass by value creates a copy of the argument, while pass
e) Inline Functions: Small functions defined with the inline keyword to reduce the overhead of
function calls.
An array is a collection of elements of the same data type stored in contiguous memory. Advantages
include:
Multidimensional arrays are arrays of arrays. For example, a 2D array is an array of 1D arrays. They
are used for representing data in rows and columns, such as matrices.
References: Aliases for other variables, providing an alternative name for the variable they refer to.