This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
When should we use the register storage specifier? |
|
Answer» If a variable is used FREQUENTLY, it should be DECLARED with the register storage SPECIFIER, and the compiler MAY allocate a CPU register for its storage to speed up variable lookup. |
|
| 2. |
What are Enumerations? |
|
Answer» Enumeration, also known as Enum in C, is a user-defined data type. It consists of constant integrals or integers that have names assigned to them by the user. Because the integer values are NAMED with enum in C, the WHOLE program is simple to learn, understand, and MAINTAIN by the same or even DIFFERENT programmer. |
|
| 3. |
What are the advantages of Macro over function? |
|
Answer» Macro on a high-level copy-paste, its definitions to places WHEREVER it is called. Due to which it saves a lot of time, as no time is SPENT while PASSING the control to a new function and the control is always with the CALLEE function. However, one downside is the size of the compiled binary is large but once compiled the program comparatively runs faster. |
|
| 4. |
What is typecasting in C? |
|
Answer» Typecasting is the PROCESS to convert a VARIABLE from one datatype to another. If we WANT to STORE the large type VALUE to an int type, then we will convert the data type into another data type explicitly. Syntax: (data_type)expression; For Example: int x;for(x=97; x<=122; x++){ printf("%c", (char)x); /*Explicit casting from int to char*/} |
|
| 5. |
Why n++ executes faster than n+1 ? |
|
Answer» n++ being a unary operation, it just needs one variable. Whereas, n = n + 1 is a BINARY operation that adds overhead to take more time (also binary operation: n += 1). However, in modern platforms, it depends on few things such as PROCESSOR architecture, C compiler, usage in your code, and other factors such as hardware problems. While in the modern compiler even if you write n = n + 1 it will get CONVERTED into n++ when it goes into the optimized binary, and it will be EQUIVALENTLY efficient. |
|
| 6. |
What is pointer to pointer in C? |
|
Answer» In C, a POINTER can also be used to store the address of another pointer. A double pointer or pointer to pointer is such a pointer. The address of a VARIABLE is STORED in the FIRST pointer, whereas the address of the first pointer is stored in the second pointer. The syntax of declaring a double pointer is GIVEN below: int **p; // pointer to a pointer which is pointing to an integer |
|
| 7. |
Difference between const char* p and char const* p? |
|
Answer» Since const char and char const are the same, it's the same. |
|
| 8. |
What is a pointer in C? |
|
Answer» A pointer is a variable that stores or POINTS to ANOTHER variable's address. The VALUE of a variable is STORED in a normal variable, WHEREAS the address of a variable is stored in a pointer variable. |
|
| 9. |
What is the difference between global int and static int declaration? |
|
Answer» The difference between this is in scope. A truly global variable has a global scope and is visible everywhere in your program. #include <stdio.h> int my_global_var = 0; int main(void) { printf("%d\n", my_global_var); return 0; }global_temp is a global variable that is visible to everything in your program, although to make it visible in other modules, you'd need an ”extern int global_temp; ” in other source files if you have a multi-file project. A static variable has a LOCAL scope but its variables are not ALLOCATED in the stack segment of the memory. It can have less than global scope, although - like global variables - it RESIDES in the .bss segment of your COMPILED binary. #include <stdio.h> int myfunc(int val) { static int my_static_var = 0; my_static_var += val; return my_static_var; } int main(void) { int myval; myval = myfunc(1); printf("first call %d\n", myval); myval = myfunc(10); printf("SECOND call %d\n", myval); return 0; } |
|
| 10. |
Why doesn’t C support function overloading? |
|
Answer» After you compile the C SOURCE, the symbol names NEED to be intact in the object code. If we introduce function overloading in our source, we should also provide name mangling as a preventive measure to avoid function name CLASHES. Also, as C is not a strictly TYPED language many things(ex: data types) are CONVERTIBLE to each other in C. Therefore, the complexity of overload resolution can introduce confusion in a language such as C. When you compile a C source, symbol names will remain intact. If you introduce function overloading, you should provide a name mangling technique to prevent name clashes. Consequently, like C++, you'll have machine-generated symbol names in the compiled binary. Additionally, C does not feature strict typing. Many things are implicitly convertible to each other in C. The complexity of overload resolution rules could introduce confusion in such kind of language |
|
| 11. |
What is recursion in C? |
|
Answer» When a FUNCTION in C calls a copy of itself, this is KNOWN as recursion. To put it another way, when a function calls itself, this TECHNIQUE is CALLED Recursion. Also, this function is known as RECURSIVE function. Syntax of Recursive Function: void do_recursion(){ ... .. ... do_recursion();... .. ...]} int main() {... .. ...do_recursion();... .. ...} |
|
| 12. |
How can a number be converted to a string? |
|
Answer» The FUNCTION takes a pointer to an array of char elements that NEED to be converted, and a FORMAT string needs to be written in a buffer as a string int SPRINTF(char *str, const char *format, ...)
The output after running the above code: Output: Value of Pi = 3.141593 |
|
| 13. |
How can a string be converted to a number? |
|
Answer» The FUNCTION takes the string as an input that needs to be converted to an integer. int atoi(const char *string)Return Value:
|
|
| 14. |
In C, What is the #line used for? |
|
Answer» In C, #line is used as a preprocessor to re-set the line number in the code, which TAKES a parameter as line number. Here is an example for the same. #include <stdio.h> /*line 1*/ /*line 2*/ int main(){ /*line 3*/ /*line 4*/ printf("HELLO world\n"); /*line 5*/ //print current line /*line 6*/ printf("Line: %d\n",__LINE__); /*line 7*/ //RESET the line number by 36 /*line 8*/ #line 36 /*reseting*/ //print current line /*line 36*/ printf("Line: %d\n",__LINE__); /*line 37*/ printf("Bye bye!!!\n"); /*line 39*/ /*line 40*/ return 0; /*line 41*/} /*line 42*/ |
|
| 15. |
What is a Preprocessor? |
|
Answer» A preprocessor is a SOFTWARE program that processes a source file before sending it to be COMPILED. INCLUSION of header files, macro expansions, conditional compilation, and LINE control are all possible with the preprocessor. |
|
| 16. |
What is a built-in function in C? |
|
Answer» The most commonly used built-in FUNCTIONS in C are sacnf(), printf(), strcpy, strlwr, STRCMP, strlen, strcat, and many more. Built-function is also known as library functions that are PROVIDED by the system to make the life of a developer easy by ASSISTING them to do certain commonly used predefined tasks. For example, if you need to PRINT output or your program into the terminal, we use printf() in C. |
|
| 17. |
What's the value of the expression 5["abxdef"]? |
|
Answer» The answer is 'f'. Explanation: The STRING mentioned "abxdef" is an array, and the EXPRESSION is EQUAL to "abxdef"[5]. Why is the inside-out expression equivalent? Because a[b] is equivalent to *(a + b) which is equivalent to *(b + a) which is equivalent to b[a]. |
|
| 18. |
What is the use of printf() and scanf() functions? Also explain format specifiers? |
Answer»
Some datatype format SPECIFIERS for both printing and SCANNING purposes are as follows:
|
|
| 19. |
What are the features of the C language? |
|
Answer» Some features of the C language are- |
|
| 20. |
Why is C called a mid-level programming language? |
|
Answer» C has characteristics of both assembly-level i.e. low-level and higher-level languages. So as a result, C is COMMONLY CALLED a middle-level language. Using C, a USER can write an operating system as well as CREATE a menu-driven consumer billing system. |
|