Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Control statement =>

In C programming, a control statement is a statement that alters the flow of execution of a


program.
There are three main types of control statements in C:
 Selection Statements (Conditional Statements)
 Iteration Statements (Loops)
 Jump Statements.
Selection Statements (Conditional Statements)=>

>>Conditional statements in C are programming constructs that allow a


program to execute different blocks of code based on whether a certain
condition is true or false. The most common types of conditional statements in C
are the if, else if, and else statements.
For example=>

**1)if (condition)

// statements to execute if condition is true

**2)

if (condition)

// statements to execute if condition is true

else

// statements to execute if condition is false

switch statement in C=>

The switch statement in C is a decision control statement that is typically used


when the user must choose between multiple alternatives.

A switch statement allows programmers to execute different blocks of code based


on the value of a single variable or expression.

For example=>
switch (expression) {
case value1:
// Code to be executed if expression == value1
break;
case value2:
// Code to be executed if expression == value2
break;
...
default:
// Code to be executed if none of the cases match
break;
}

Iteration Statements (Loops)=>

We use loops it to execute a block of code repeatedly based on a condition or a


set of conditions. We have primarily three types of iteration statements: for
loop, while loop, do-while loop.
For loop=>
The for loop in C is a programming construct that allows us to execute a block
of code repeatedly, until a specific condition is met. The syntax for a for loop is
as follows:

Syntax=>
for (initialization; condition; update) {
// code to be executed
}
while loop=>
A while loop in C is a control flow structure that allows for a piece of code to be
executed repeatedly as long as a particular condition is true.

Syntax:

while (condition) {
// code to be executed
}

do-while loop=>
The do-while loop checks the condition after executing the loop body,
which ensures that the loop body is executed at least once, even if the
condition is initially false.

So even if a condition is false in the first place, the do-while loop would have
already run once. A do-while loop is very much similar to a while loop, except for
the fact that it is guaranteed to execute the body at least once.
Syntax:
do {
// code block
} while (condition);

Jump statement:
Jump Statement in C is used in C programming language to
transfer control from one part of the program to another.
There are four types of Jump Statements in C: break,
continue,return and goto. While these statements can be useful in
certain situations, they can also lead to errors if not used properly.
Nested loop=>
A nested loop is a loop inside another loop. The most common nested loop is a
for loop.
For example =>

// outer loop

for (int i = 1; i <= 5; ++i) {

// codes

// inner loop

for(int j = 1; j <=2; ++j) {

// codes

**Nested loops are also called "loop inside loops"

Ladder conditions=>
if else if ladder in C programming is used to test a series of conditions sequentially.

For example =>


void main() {
int number;

printf("Enter a number: ");


scanf("%d", &number);

if (number > 0) {
printf("The number is positive.\n");
}

else if (number < 0) {


printf("The number is negative.\n");
}
else {
printf("The number is Zero\n");
}

getch();
}

Error in c
Errors in C language are defined as an illegal operations performed
by the user, resulting in the abnormal or abrupt working of the
program logic.
An error in C programming is an issue that causes the program to not work as
intended, or to crash. Errors can be caused by mistakes in the code, incorrect input,
or hardware problems.
There are five different types of errors in C Programming
like Syntax Error, Run Time Error, Logical Error, Semantic Error,
and Linker Error.

*Syntax errors:
These errors occur when the code does not follow the rules of the C language. For example, a missing
semicolon or an incorrect spelling.

*Run-time errors:
These errors occur when the program is running. For example, trying to divide by zero or accessing an
element that is out of bounds can cause a run-time error.

*Logical errors:
These errors occur when the code does not produce the desired output. For example, a loop that never
ends

*Linker errors:
These errors occur when the linker cannot find the libraries that the program needs. For example, if the
program tries to use a function that is not in a linked library, a linker error will occur.

Unary and Binary operator


Unary and binary operators are two general classes of operators. Unary operators
perform an action with a single operand, while binary operators perform
actions with two operands.
*Unary operators:

 Perform an action on one operand


 Produce only one result
 Typically appear with their operand in the following format: operator operand

*Binary operators:

 Perform actions with two or more operands


 Appear with their operands in the following format
 Include four types of operations: binary addition, binary subtraction, binary
multiplication, and binary division
Bit-wise Operators
The bitwise operators are used to perform bit-wise operations on operands or
variables. e.g. bit-wise AND operation, bit-wise OR operation, etc.
Important questions
Identifier =>
An identifier is a sequence of characters in the code that identifies a
variable, function, or property.

Basic Structure of C lang.


The structure of a C program means the specific structure to start the programming in the C
language. Without a proper structure, it becomes difficult to analyze the problem and the
solution.

-----------Question paper
Q1. what is control statement ? [5]
Q2. Explain variable, Identifiers and keywords with
example. [5]
Q3. difference between selection and looping
statements. [5]
Q4. difference between while loop and do while loop.
[5]
Q5. describe the structure of C program. [5]
Q6. what is unary and binary operators ? explain[5]
Q7. what is error ? Explain types of error[5]
Q8. what is Nested loop and Ladder conditions ? Give
Example. [5]
Q9. Difference between switch case and if, else if,
else. [5]
Q10. Who was the founder of C lang. ? [5]

You might also like