You are on page 1of 4

2.

20 Vnit Tue
Difference Between break and continue are listed below.

Break Continue
A break can appear inboth switch and A continue can appear only in loop (for,|

loop (for, while, do) statements. while, do) statements.

A break causes the switch or loop A continue doesn't terminate the loop, it
statements to terminate the moment it | causes the loop to go to the next iteration.
is executed. Loop or switch ends All iterations of the loop are executed
abruptly when break is encountered. even if continue is encountered. The
continue statement is used to skip
statements in the loop that appear after
the continue.
The break statement can be used in | The continue statement can appear only
both switch and loop statements. in loops. You will get an error if this
appears in switch statement.
When a break statement is When a continue statement sis
encountered, it terminates the block encountered, it gets the control to the
and gets the control out of the switeh next iteration of the
loop.
or loop
A break causes the innermost A continue inside a loop nested within a
enclosing loop or switch to be exited switch causes the next loop iteration
immediately.
Q.2. Write the syntax of ternary
operator and write a
program to find the biggest from
four numbers by using
ternary operator.
Ans. Syntax of ternary operator:
val =condition ? vall val2;
Program to find the biggest from four numbers using ternary operator
#includecstdio.h>
#include <conio.h>
int main)

int n1=8, n2=7, n3=9, n4=6;


int t1, t2, largest;
t1 =(n1>n2? nl: n2);

2 (n3> n4? n3:n4);


2.21
largest (tl > t2? tl: t2);
printf("largest = %d",largest);

getch(
return 0;

Q.3. Compare and contrast the switch with if-else-ladder with example.
Ans.
Ans. If-else-ladder and switch case both are used to control the flow of program.
Difference Between switch and if-else-ladder are listed below.

If-else switch

Expression inside if statement decide expression inside switch statement decide


whether to execute the statements inside if which case to execute.
block or under else block.

You can have multiple if statement for In switch you only have one expression for
multiple choice of statements. the multiple choices.

If-else statement checks for equality as switch checks only for equality.
well as for logical expression.

The if statement evaluates integer, switch statement evaluates only character or


character, pointer or floating-point type or a integer datatype.
boolean type.
Sequence of execution is like either | The expression in switch statement decide
statement under if block will execute or which case to execute and if you do not
statements under else block statement will apply a break statement after each case it
execute. will execute till the end of switch statement.

Ifexpression inside if turn outs to be false, If expression inside switch statement turn
statement inside else block will be out to be false then default statements is
executed. executed.

4Compare and contrast the entry controlled loop and exit controlled loop with
suitable example program. IDec 2017]
n5, Loop is a group of instructions compiler executes repeatedly while some condition

remains true.
Loops are classified into two types. They are Entry control loop and Exit cono

loop
Entry control loop:
n this control loop compiler will check condition first. If condition is true then
2.22 Vnit Tu
compiler move into the body. If condition fail compiler doesn't execute body atleast
once. Entry control loop is also called as Pre-checking control loop. Ex: while, for
Exit control loop:
In this kind of control loop compiler first executes the body then it go for the
condition. If condition is true again it goes to the body. If condition fails it goes out
of the body. So in exit control loop without knowing condition compiler execute
body minimum one time. Exit control loop is also as post control loop.
Q.5. Discuss about Multi-way conditional statement with suitable examples.
Ans. A multi-way selection statement is used to execute at most ONE of the choices of a
set of statements presented.

Syntax of the multi-way select statement:


switch (EXPRESSION )

case CONSTANT1:
one or more statements;

break;
case CONSTANT2:
one or more statements;

break;

[default one or more statements;]

Q.6. What is the use of input and output functions


in C?
Ans. Two commonly used functions for 1/O (Input/Output) are printf() and scanf(). The
scanf) function reads formatted input from standard input (keyboard) whereas the
printf() function sends formatted output to the standard output (monitor).
Q.7. What is conditional Statement?

Ans. Which perform different computations or actions depending on whether a


programmer-specified Boolean condition evaluates to true or false.( if,if-else,nested
if-else).
Q.8. What is looping Statement?
Ans. A loop is a way of repeating a statement a number of times until some way of endin
the loop occurs. It might be run for a preset number of times, typically in a for loop
repeated as long as an expression 1s true (a while loop) or repeated until an

expressionbecomes false in a do while loop.


Vnit wor
2.23
Q.9.
Q.9. What is difference between while and do while?
Ans. Only difference between these two loops is that, in while loops, test expression is
checked at first but, in do...while loop code is executed at first then the
condition is
checked. So, the code are executed at least once in do...while
loops.
Q.10. What is Switch statement?
Ans. A switch statement is a
type of selection control mechanism used to allow the value
of a variable or
expression to change the control flow of
program execution via a
multiway branch.
Q.11. What is nested loop?
Ans. A nestedloop is a loop within a loop, an inner loop within the body of an outer one.
How this works is that the first
pass of the outer loop triggers the inner loop, which
executes to completion. Then the second
pass of the outer loop triggers the inner
loop again. This repeats until the outer loop finishes.
Q.12. What are character input and
output functions?
Ans. The int
getchar(void) function reads the next available character from the screen and
returns it as an
integer. The int putchar(int c) function puts the passed character on
the screen and returns the same
character.

You might also like