C Interview Questions

1. What is C language?

Answer:- C is a general purpose, procedural programming language and developed at Bell labs by Dennis Ritchie in 1972-73. It is widely used programming language particularly used for system programming because it produces code that runs nearly as fast as the code written in assembly language. Today most of the operating systems are written in C language. C is a middle level language since it has feature of both low and high level language.


2. What are the features of C programming language?

Answer:-

Fast & Efficient: Programs Written in C are efficient and fast. This is due to its variety of data type and powerful operators.
Portable: C can run on any machine with little or no modifications.
Middle Level Language: It include feature of both high and low level programming language.
Structured: It divides the problem into smaller modules called functions or procedures.
Extensible: C is an extensible language as it can adopt new features.


3. Explain some real life applications of C programming language?

Answer:- Some of the real life applications of C programming language are -

1. Operation System
2. Development of new language
3. Embedded System
4. Computation Platforms
5. Graphics and Games


4. What are the fundamental data types in C programming?

Answer:- integer(int), floating point(float), character(char) and void.


5. What are the return values of printf and scanf?

Answer:-

printf() returns total number of characters printed and if there is some error then it returns a negative value.
scanf() returns the total number of input values that are scanned and if there is some input failure or error then it returns EOF.


6. What is difference between i++ and ++i?

Answer:- i++ is known as Post Increment in which first value is used and then incremented whereas ++i is called Pre Increment in which value is first incremented and then used.


7. What is the use of static variable in c?

Answer:- A static variable is a variable whose lifetime doesn’t end with a function call where it is declared. All calls to the function share the same copy of static variables. For example static variables can be used to count the number of times a function is called. Also, static variables get the default value as 0. It is initialized only once in the memory heap to reduce the memory usage.


8. What is volatile keyword?

Answer:- The volatile keyword is intended to prevent the compiler from applying any optimizations on variable that can change in ways that cannot be determined by the compiler. Variables declared as volatile are omitted from optimization because their values can be changed by code outside the scope of current code at any time.


9. How negative values are stored in c?

Answer:- Negative numbers are stored in 2's compliment form.


10. What is a dangling pointer?

Answer:- Dangling pointer is a pointer variable which holds the address (integer value) of that memory location which is removed or doesn't exist or you can say a pointer pointing to a memory location that has been deleted is called dangling pointer.


11. Can a program be compiled without a main() function?

Answer:- Yes, we can compile a C program without main function but it will not be exceuted as its execution starts from the main function only.


12. What is lvalue and rvalue?

Answer:- The value which appears on left side of assignment operator is called as lvalue while which appears on right side is called rvalue.


13. What are command line arguments?

Answer:-Command line argument is used to pass the values to the main() function of any program. By command line argument we are actually passing values to our C program when they are executed. Command line arguments are given after the name of the program in command line shell of Operating Systems.


14. What is recursion?

Answer:- Recursion is the process in which function call itself. Recursive functions are very useful to solve many mathematical problems.


15. What is the difference between malloc and calloc?

Answer:- Both malloc and calloc are used in C programming language for dynamic memory allocation they obtain blocks of memory dynamically. The fundamental difference that exists between malloc and calloc in C language is calloc() requires two arguments while malloc() require one argument. malloc() doesn’t initialize the allocated memory while calloc() allocates the memory and also initializes the allocated memory block to zero


16. What is the difference between Call by Value and Call by Reference?

Answer:- There are two ways to pass arguments or parameters to function calls - call by value and call by reference. In call by value the value of the actual parameters are copied into the formal parameters and operations are applied on copied value not on original value while in call by reference the address of the variables are passed into the function call as the actual parameter and operations are performed on actual values i.e actual values are altered.


17. What are header files and its uses?

Answer:- Header files are also known as library files. They contain two essential things: the definitions and prototypes of functions being used in a program. Header Files are included in the beginning of the program. It is a predefined code and we have to simply include the file. It has .h extension. It contains C declarations and macro definition. For eg - stdio.h


18. What are the different file extensions involved when programming in C?

Answer:- Source code is saved with .c extension and when compiled it generate .obj file and .exe file. Also we have header files with extension .h


19. What is the difference between functions abs() and fabs()?

Answer:- Both funtion are used to get the absolute value only difference is that abs() is used for integer values while fabs() is used for floating numbers.


20. What are actual and formal parameters?

Answer:- Actual parameters are the parameters that are passed with function call while parameters or arguments which are mentioned in the definition of the function is called formal arguments.


21. What is the difference between structure and union?

Answer:- Structure and union both are user defined data types which contains variables of different data types. Both of them have same syntax for definition, declaration of variables and for accessing members. The only difference is that in a structure all members gets memory allocated while in union compiler allocates the memory for the largest of all members and in a union all members have offset zero from the base and only one variable can be used at a time in union.


22. What is the difference between getchar and getch?

Answer:- getchar() is a standard function that gets a character from the stdin while getch() is non-standard it gets a character from the keyboard (which may be different from stdin) and does not echo it.


23. What is type casting in c?

Answer:- Type casting is a way to convert a variable from one data type to another data type. For example you can convert double value to integer. Typecasting is of 2 types implicit and explicit. Implicit conversions do not require any operator for converted. They are automatically performed when a value is copied to a compatible type in the program. The type conversion performed by the programmer by posing the data type of the expression of specific type is known as explicit type conversion.


24. What is a void pointer?

Answer:- A Void pointer is a generic pointer in programming. If the pointer type is unknown, we make use of the void pointer. A void pointer is a pointer that has no associated data type with it. A void pointer can hold address of any type and can be typcasted to any type.


25. Explain pointers in C programming?

Answer:- Pointers in C Programming Language is a variable that stores the address of another variable. To access address of a variable to a pointer, we use the unary operator & (ampersand) that returns the address of that variable. For example &q gives us address of variable q. A Pointer in C is used to allocate memory dynamically i.e. at run time. * is used to denote that p is pointer variable and not a normal variable.


26. What is the use of a semicolon (;) at the end of every program statement?

Answer:- Semicolon is a statement terminator in C to help the parser figure out where the statement ends since, by default statements in C can have any number of lines.


27. What is the difference between declaration and definition of a function?

Answer:- Declarations tell the compiler that a program element or name exists. A declaration introduces one or more names into a program. Declarations can occur more than once in a program. Function declaration declares the name of the function and the type of what it returns. Definitions specify what code or data the name describes. A name must be declared before it can be used. A function definition defines the function body, and defines what happens when the function is called.


28. What is memory leak?

Answer:- In computer science, a memory leak is a particular type of unintentional memory consumption by a computer program where the program fails to release memory when no longer needed. This condition is normally the result of a bug in a program that prevents it from freeing up memory that it no longer needs.


29. What is scope of variable in c?

Answer:- A scope is a region for the variable where the variable can be accessible. Global variables hold their values throughout the lifetime of the program and they can be accessed inside any of the functions defined for the program. while variables that are declared inside a function or block are called local variables.


30. What is the difference between near, far and huge pointers?

Answer:- near, far and huge pointers were extensions to C to allow the programmer to give hints to the compiler about how to implement a pointer in the horrific segmented memory architecture of the Intel 8086/8088 (and 80186) CPUs. Those CPUs used two 16 bit registers (and variously sized offsets) to generate a 20-bit address.
Near pointer is used to store 16 bit addresses means within current segment on a 16 bit machine. The limitation is that we can only access 64kb of data at a time. A far pointer is typically 32 bit that can access memory outside current segment. To use this, compiler allocates a segment register to store segment address, then another register to store offset within current segment. Huge pointer is also typically 32 bit and can access outside segment. In case of far pointers, a segment is fixed. In far pointer, the segment part cannot be modified, but in Huge it can be.







Also check :


Discussion


* You must be logged in to add comment.