Have a Question? It will be answered as soon as possible. Check Object Oriented Interview Questions for more Object Oriented Interview. Economics Interview Questions and Answers Guide will explain us now that Economics is the social science that studies the production, distribution, and consumption of.
Interesting C Interview Questions and Answers. In this article, we will discuss some interesting problems on C language that can help students to brush up their C programming skills and help them prepare their C fundamentals for interviews. Can you detect it?#include< stdio.
This function accepts a string from stdin without checking the capacity of buffer in which it copies the value. This may well result in buffer overflow. The standard function fgets() is advisable to use in these cases. Can you break it without knowing the password?#include< stdio. The authentication logic in above password protector code can be compromised by exploiting the loophole of strcpy() function. This function copies the password supplied by user to the .
So if a user supplies a random password of such a length that causes buffer overflow and overwrites the memory location containing the default value . In my case also, the gcc does this by default so I had to use the the compile option . Return type of main()Question: Will the following code compile?
If yes, then is there any other problem with this code?#include< stdio. Return type of main() should be . This is because the . This becomes important especially when the program is being run as a part of a script which relies on the success of the program execution. Memory Leak. Question: Will the following code result in memory leak?#include< stdio. Since the program terminates so all the memory allocated by the program is automatically freed as part of cleanup. But if the above code was all inside a while loop then this would have caused serious memory leaks.
Note : If you want to know more on memory leaks and the tool that can detect memory leaks, read our article on Valgrind. The free() function. Question: The following program seg- faults (crashes) when user supplies input as .
C Programming Questions and Answers - Learn ANSI, GNU and K/R standard of C programming language with simple and easy examples covering basic C, language basics.
Why?#include< stdio. But in case of . Can you tell why?#include< stdio. This function does not call the clean- up functions like atexit() etc.
If atexit() is required to be called then exit() or . Also, is there a way in which more than one arguments can be passed to it? Answer: A function that can accept any type of argument looks like : int func(void *ptr)if more than one argument needs to be passed to this function then this function could be called with a structure object where- in the structure members can be populated with the arguments that need to be passed. Going by this logic, ptr++ is evaluated first and then *ptr. So both these operations result in .
Now since a post fix . Making changes in Code(or read- only) segment. Question: The following code seg- faults (crashes). Can you tell the reason why?#include< stdio. This operation is invalid and hence causes a seg- fault or a crash.
Process that changes its own name. Question: Can you write a program that changes its own name when run? Answer: Following piece of code tries to do the required : #include< stdio. Check the process. Returning address of local variable.
Question: Is there any problem with the following code? If yes, then how it can be rectified?#include< stdio. This function returns the address of a local variable. Since the life time of this local variable is that of the function .
This can be avoided by passing the address of variable . Processing printf() arguments. Question: What would be the output of the following code?#include< stdio.