Commonly Asked C Programming Interview Questions | Set 3
1. Differentiate between getch() and getche()?
Ans: Both the functions are designed to read characters from the keyboard and the only difference is that
getch(): reads characters from the keyboard but it does not use any buffers. Hence, data is not displayed on the screen.
getche(): reads characters from the keyboard and it uses a buffer. Hence, data is displayed on the screen.
2. Explain toupper() with an example?
Ans: toupper() is a function designed to convert lowercase words/characters into upper case.
3. Explain Local Static Variables and what is their use?
Ans: A local static variable is a variable whose life doesn’t end with a function call where it is declared. It extends for the lifetime of the complete program. All calls to the function share the same copy of local static variables.
4. What is the difference between declaring a header file with < > and ” “?
Ans: If the Header File is declared using < > then the compiler searches for the header file within the Built-in Path. If the Header File is declared using ” ” then the compiler will search for the Header File in the current working directory and if not found then it searches for the file in other locations.
5. Which variable can be used to access Union data members if the Union variable is declared as a pointer variable?
Ans:
Arrow Operator( -> ) can be used to access the data members of a Union if the Union Variable is declared as a pointer variable.
6. What are the different storage class specifiers in C?
Ans: The different storage specifiers available in C Language are as follows:
- auto
- register
- static
- extern
7. What is typecasting?
Ans: Typecasting is a process of converting one data type into another is known as typecasting. If we want to store the floating type value to an int type, then we will convert the data type into another data type explicitly.
8. How can you print a string with the symbol % in it?
Ans: There is no escape sequence provided for the symbol % in C. So, to print % we should use ‘%%’ as shown below.
printf(I got 95%% in last year exams.");
9. Explain the # pragma directive.
Ans: The following points explain the Pragma Directive.
- This is a preprocessor directive that can be used to turn on or off certain features.
- It is of two types #pragma startup, #pragma exit and pragma warn.
- #pragma startup allows us to specify functions called upon program startup.
- #pragma exit allows us to specify functions called upon program exit.
- #pragma warn tells the computer to suppress any warning or not.
10. Differentiate between the macros and the functions?
Ans: Preprocessor is a macro processor which is automatically used by the compiler to transform the program before its actual compilation.