Skip to content

C Programming Interview Questions 003

Dibyendu Barman edited this page Dec 9, 2022 · 2 revisions

Q1. Can I create a customized Head File in C language?
Ans: It is possible to create a new header file. Create a file with function prototypes that need to be used in the program. Include the file in the ‘#include’ section in its name.

Q2. What do you mean by Memory Leak?
Ans: Memory Leak can be defined as a situation where the programmer allocates dynamic memory to the program but fails to free or delete the used memory after the completion of the code. This is harmful if daemons and servers are included in the program.

Q3. 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.

Q4. 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.

Q5. When should we use the register storage specifier?
Ans: We use Register Storage Specifier if a certain variable is used very frequently. This helps the compiler to locate the variable as the variable will be declared in one of the CPU registers.

Q6. Which statement is efficient and why? x=x+1; or x++; ?
Ans: x++; is the most efficient statement as it is just a single instruction to the compiler while the other is not.

Q7. Can I declare the same variable name for the variables which have different scopes?
Ans: Yes, the Same variable name can be declared to the variables with different variable scopes as in the following example.
int var;
void function()
{
int variable;
}
int main()
{
int variable;
}

Q8. 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.

Q9. 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**

Q10. 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.
Syntax:
(type_name) expression;

Clone this wiki locally