Sunday, October 5, 2025

C Interview Questions & Answers || Intermediate Level || Set - II

Question: How to convert a string to numbers in C? 

Answer: You can talk about different methods for this conversion. The first method uses the stoi() library function. The second method uses the atoi() library function.

Question: What is the difference between call by value and call by reference in C? 

Answer: Call by value denotes that the argument value is imitated (copied) into the parameter. Call by reference indicates that the reference argument gets passed to the parameter.

Question: What is a NULL pointer in C? 

Answer: A null pointer lacks any valid address and is usually assigned to NULL or zero. This macro constant can be found in different C programming header files, including stdio.

Question: What is static memory allocation? 

Answer: Static memory allocation is performed during compile time, which can help save running time. It is highly preferred in the array and is usually performed from the stack.

Question: What is the difference between malloc() and calloc()? 

Answer: The malloc() function is utilized for making a single memory block of a certain size. If you want to assign more than one memory block to one variable, you can leverage the calloc() function.

Question: What is the purpose of the sprintf() function? 

Answer: The sprintf() function allows you to format and store a series of values and characters within the array buffer.

Question: What functions are used to open and close the file in C language? 

Answer: The function used to open an existing file using the C programming language is fopen(). The function used to close a file using the C programming language is fclose().

Question: What is the program for swapping two numbers without any third variable? 

Answer: The program can swap two numbers using arithmetic operations without a third variable, for example:

int a=20, b=10;

a=a+b; // a becomes 30 (20+10)

b=a-b; // b becomes 20 (30-10)

a=a-b; // a becomes 10 (30-20)

// Output: Before swapping a=20 b=10; After swapping a=10 b=20


Question: What is an r-value and l-value? 

Answer: An “lvalue” denotes an object with an address, which means it has an identifiable memory location. It is usually located on the left or right side of the assignment operator. An “r-value” comes without any address or identifiable memory location. Because it cannot be allocated to a value, you will find it only on the right side of an assignment operator.

…till next post, bye-bye & take care.

No comments:

Post a Comment