- Home
- Interview Questions
- C Programming
Yes, a while statement can accomplish the same task as a for statement, but you need to do two additional things. You must initialize any variables before starting the while command, and you need to increment any variables as a part of the while loop.
You can’t overlap the loops. The nested loop must be entirely inside the outer loop.
Yes, a while statement can be nested in a do...while loop. You can nest any command within any other command.
The four parts of a for statement are the initializer, the condition, the increment, and the statement(s).
The two parts of a while statement are the condition and the statement(s).
Because printf() does more, it has additional overhead. When you’re trying to write a small, efficient program, or when your programs get big and resources are valuable, you will want to take advantage of the smaller overhead of puts(). In general, you should use the simplest available resource.
stdio.h contains the prototypes for the standard input/output functions. printf(), puts(), and scanf() are three of these standard functions. Try running a program without the stdio.h header and see the errors and warnings you get.
This is an easy mistake to make. Unpredictable results can occur if you forget the address of operator. When you read about pointers on Days 9 and 13, you will understand this better. For now, know that if you omit the address of operator, scanf() doesn’t place the entered information in your variable, but in some other place in memory. This could do anything from apparently having no effect to locking up your computer so that you must reboot.
There are two differences between puts() and printf():
printf() can print variable parameters.
puts() automatically adds a newline character to the end of the string it prints.
a. \\
b. \b
c. \n
d. \t
e. \a
a. \\ prints a backslash.
b. \b prints a backspace.
c. \n prints a newline.
d. \t prints a tab.
e. \a (for "alert") sounds the beep.