Topics |
|---|
1. Write about switch statement.
The switch statement handles a series of decisions by checking a particular variable or expression for different values it may assume and based on which different actions are taken. In most programs, it is necessary to include a break statement at the end of each case section. Several cases can execute the same statements by isting the case labels together before the statements.
The format of switch statement is
switch(expression)
{
case (expression 1):
c++ statements;
break;
case ( expression 2):
c++ statements;
break;
}
2. What is a loop?
A loop is a group of instructions the computer executed repeatedly until some
terminating condition is satisfied.
3. What is a loop counter?
A loop counter is used to count repetitions for a group of instructions.
4. How will you use For statement?
This is probably the most useful and the most used loop in C/ C++. The statements in the loop repeat continuously a certain number of times. The format is:

the above statement will be executed 10 times and the values 1 to 10 will be printed.
5. Explain while statement.
The while loop allows program to repeat a statement or series of statements,overand over, as long as a certain test condition is true.
The while loop is an entry-condition loop. If the test condition is false to begin with, the program never executes the body of the loop. The format of while statement is :
while(test expression)
{
Program statements;
}
6. Write about do-while statement.
It is very similar to the while loop. The only difference being, in a ‘while’ loop, the condition is checked before hand ,but in a d0-while loop the condition is checked after one execution of the loop. This ensures that the body of the loop executes atleast once. The do while loop is an exit- condition loop. This means that the body of the loop is always executed first. Then the test condition is evaluated. The syntax of the do – while loop is:
do
{
Program statements;
}while (test expression);
7. What do you mean by nested loop?
The placing of one loop inside body of another loop is called nesting. When you “nest” two loops, the outer loop takes control of the number of complete repetitions of inner loop. While all the types of loops may be nested, the most commonly nested loops are for loops.

8. Write about exit() function.
The exit() function ends a program before its normal termination. It requires the standard library header file, stdlib.h or process.h. the format is:
exit(value);
Where value is an integer value or variable. You must include the stdlib.h header file when using exit() function.
9. Write about break statements.
The break statement gets you out of a loop. No matter what the loop’s ending condition. The program continues with the next statement immediately following the loop. Break stops only the loop in which t resides. It does not break out of a nested loop. The format of break statement is:
Break;
10. Write about continue statement.
The continue statement, when executed in one of the repetition structures (for,while and do/while), skips any remaining statements in the body of the structure and proceeds with the next iteration of the loop. The format is:
Continue;
11. What is the use of go to statements?
The goto statement causes the control to be shifted to a different location unconditionally, instead of executing the next statement in the sequence. The format of the goto statement is;
Goto statement label;
12. What do you mean by stdin?
C++ always assumes that input will come from stdin,means standard input device. It is usually the keyboard, although you can re-route this default. The reason why cin gets input from the keyboard is that most computers consider the keyboard to be the standard input device.
13. What is stdout?
C++ assumes that the output would go to stdout, or the standard output device. The reason that cout goes to the screen is simply that stdout is directed to the screen, by default, on most computers.
14. Write about get() function.
The get() function inputs a single character from the standard input device( the keyboard, if you do not redirect it.) the format of get() is
Device.get(char_var);
15. Write about put() function.
The put function outputs a single character to the standard output device( the screen, if you do not redirect it from the operating system). The format of put() is:
Device.put(char_var);
Ex:
cout.put(name);
16. Explain getch() function.
This function reads a character from the keyboard but does not show it on the screen.
The format is :
char var;
var = getch();
17. Write about putch() function.
This function directly writes a character on the console. The format of putch() is:
putch(char_var);
18. What is the application of getchar() function?
The C++ library uses getchar() function to return a single character to a variable from a standard input device (typically a keyboard). The general form of the getchar() function is:
char_ var=getchar();
Where char_val refers to some previously declared character variable.
19. How will you use putchar() function?
When the statndard C++ function that prints or displays a single character to(by sending it to standard output) is called putchar(). The general form of the putchar() function is:
putchar(char_val);
20. Write about gets() function.
The gets() function gets a string from stdin. The format of the gets is:
gets(line_char);