C Programming Interview Questions and Answers - 8

Question: 36

What will happen if break statement is not used in switch case in C?

Switch case statements are used to execute only specific case statements based on the switch expression.

If we do not use break statement at the end of each case, program will execute all consecutive case statements until it finds next break statement or till the end of switch case block.

Question: 37

What is the difference between auto variable and register variable in C?

Storage class of all variables is auto by default unless we specify a variable is register or static or extern in C program.

Register variables will be accessed very faster than the normal/auto variables.

Since they are stored in register memory rather than main memory.

But only limited variables can be used as register since register size is very low. (16 bits, 32 bits, or 64 bits).

Question: 38

Can the “if” function be used in comparing strings?

No. “ if”command can only be used to compare numerical values and single character values.  For comparing string values, there is another function called strcmp that deals specifically with strings.

Related Questions