Programming With C
Programming With C
PROGRAMMING WITH C
Page no. -1
COMPUTER SCIENCE PRANAB SAHA(B.Sc(H), MCA) 9088134887
12) What is escape sequence? Discuss all the escape sequence in details?
Ans.Escape sequences are used to control the way the cursor moves on the screen or insert/display some special
characters.
Escape sequence Use
\n New Line
\t Tab space
\b Back space
\r move the cursor move the cursor to the beginning of
the same line
\f Eject the current page when output is sent to the
printer.
Ans. When an single operand or variable is needed to work any operation these operators are called unary operators.
Ex. - ++(increment operator), --(decrement operator), +=(increment operator), -=(decrement operator), *=(multiplication
operator), /=(divisional operator), %=(modulus operator).
Suppose , int a=5;
a++ or a+=1 ; //is incremented i’s value by 1.
23) What is pre increment & post increment in C?
Ans. When an unary operator is placed before a variable or operand then it is called pre increment.
Ex. – int x=1;
Printf(“%d”,x);
++x;
Printf(“%d”,x);
Output will be 2 using pre increment operator.
When an unary operator is placed after a variable or operand then it is called post increment.
Ex. – int x=1;
Printf(“%d”,x);
x++;
Printf(“%d”,x);
Output will be 2 using post increment operator.
[ Note :in the same manner pre decrement & post decrement operators are used in C].
24) What is the difference between (While loop & For loop )with Do While loop.
Ans.
For / While Loop Do While Loop
1) they are called Entry controlled loop. 1) It os called Exit called loop.
2) Here if the condition is not satisfied then loop will 2) Here atleast once loop will execute because after
not entered into the loop & exit automatically. execution of loop 1 time the condition will check.
3) If the condition is not satisfied then the loop will not 3) Here the loop will execute atleast once.
execute once.
4)Ex. – 4) Ex.-
int i; int i=1;
for(i=1;i<=0;i++) do
{ {
Printf(“%d\n”,n); Printf(“%d\n”,i);
} }while(i<=0);
Loop will not execute as the condition is dissatisfied. Loop will execute atleast once as there is no
condition as the entry point of the loop.
25) What is continue statement in C? Discuss with example.
Ans. The continue statement is used to take the control to the beginning of the loop, bypassing certain statements within
the body of the loop. To use continue statement there should be an if statement which will check the condition.
Ex. - // WAP to print odd no. within a given range.
#include<stdio.h>
#include<conio.h>
void main()
{
int ctr=1,i=1;n;
printf(“Enter the Range”); scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
{
Continue;
}
Printf(“%d”,i);
}
getch();
}
26) What is the difference between break & continue statement?
Ans.
Break Continue
1) is used to forcefully come out of the loop or switch 1) is used to take the control to the beginning of the
case or program by bypassing the normal condition loop, bypassing certain statements within the body the
test or terminate a case in switch statement. loop.
2) break statement can be used in both switch case & 2) continue statement can be used in loop statement
loop statement. only.
3) It is used to goes out of the loop or switch. 3) It is used to continue the loop , by skipping some
portion of the loop.
Page no. -3
COMPUTER SCIENCE PRANAB SAHA(B.Sc(H), MCA) 9088134887
27) What is the diff. between for loop and while loop?
Ans. –
Page no. -4