C Interview Questions and Answers – Part 2 (For Freshers and Beginners)

Mou

October 29, 2025

C Interview Questions and Answers – Part 2 (For Freshers and Beginners)

If you’ve already gone through the first part of our C Interview Questions for Freshers, this second part will help you take your preparation one step ahead.
Here, we’ll discuss slightly advanced but easy-to-understand C concepts that are often asked in technical interviews.

Let’s get started 👇


31. What is the difference between array and pointer in C?

Answer:
An array is a collection of similar data types stored in continuous memory, while a pointer is a variable that stores an address of another variable or array.

Example:

int arr[3] = {10, 20, 30};
int *ptr = arr;
printf("%d", *(ptr+1)); // prints 20

Here, both array name arr and pointer ptr can be used to access array elements.


32. What is pointer arithmetic?

Answer:
Pointer arithmetic means performing operations like addition or subtraction on pointers.
It is mostly used to move between memory locations.

Example:

int a[3] = {10, 20, 30};
int *p = a;
p++;  // moves to next element
printf("%d", *p); // prints 20

33. What is a NULL pointer?

Answer:
A NULL pointer doesn’t point to any valid memory location. It’s often used to check if a pointer has a valid address or not.

Example:

int *ptr = NULL;
if(ptr == NULL)
   printf("Pointer is empty");

34. What are function pointers in C?

Answer:
A function pointer stores the address of a function. It allows functions to be passed as arguments.

Example:

void greet() { printf("Hello"); }
int main() {
   void (*ptr)() = greet;
   ptr(); // calls greet()
}

35. What is the difference between structure and union?

Answer:

StructureUnion
Each member has separate memory.All members share the same memory.
Total size = sum of all members.Size = size of largest member.
Used when storing different data together.Used when saving memory is important.

Example:

struct student { int id; float marks; };
union data { int id; float marks; };

36. What is enumeration (enum) in C?

Answer:
enum is a user-defined data type that assigns names to integer constants for better readability.

Example:

enum week {Sun, Mon, Tue, Wed, Thu, Fri, Sat};
enum week today = Wed;
printf("%d", today); // prints 3

37. What is the difference between typedef and #define?

Answer:

  • typedef gives a new name to an existing data type.
  • #define is used for macros or constants.

Example:

typedef unsigned int UINT;
UINT age = 25;

#define PI 3.14

38. What is a static variable in C?

Answer:
A static variable keeps its value even after a function ends. It is stored in a fixed memory area.

Example:

void count() {
    static int c = 0;
    c++;
    printf("%d ", c);
}

Every time count() is called, c retains its previous value.


39. What is recursion vs iteration?

Answer:

RecursionIteration
Function calls itself.Code repeats using loops.
Uses more memory.Uses less memory.
Easier for problems like factorial, Fibonacci.Easier for simple repetitions.

40. What is the difference between gets() and scanf() for strings?

Answer:

  • scanf() reads only one word until space.
  • gets() reads the full line (but it’s unsafe, may cause buffer overflow).

Example:

char name[50];
gets(name);
printf("%s", name);

41. What is the use of fgets() in C?

Answer:
fgets() is a safer alternative to gets() for reading strings.
Example:

fgets(name, sizeof(name), stdin);

42. What are file handling functions in C?

Answer:
File handling is used to read and write data to files.
Common functions:

  • fopen() – opens a file
  • fclose() – closes a file
  • fprintf() – writes data
  • fscanf() – reads data
  • fgets() – reads string from file
  • fputs() – writes string to file

Example:

FILE *f = fopen("data.txt", "w");
fprintf(f, "Hello World!");
fclose(f);

43. What is the difference between text and binary file in C?

Answer:

Text FileBinary File
Data stored in human-readable form.Data stored in binary (0s and 1s).
Example: .txtExample: .bin
Slower processing.Faster and compact.

44. What is memory leak in C?

Answer:
Memory leak occurs when memory is allocated dynamically (using malloc() or calloc()) but not freed using free().
This causes unnecessary memory usage.

Example:

int *ptr = (int*)malloc(10 * sizeof(int));
// free(ptr); missing -> memory leak

45. What is segmentation fault?

Answer:
A segmentation fault happens when a program tries to access memory that it is not allowed to (like using invalid or NULL pointers).


46. What is preprocessor in C?

Answer:
A preprocessor is a program that executes before compilation. It handles directives like #include, #define, and #ifdef.


47. What is conditional compilation?

Answer:
Conditional compilation allows certain parts of the code to be compiled only if specific conditions are met.

Example:

#ifdef DEBUG
printf("Debug mode on");
#endif

48. What is the difference between pass by value and pass by reference in C?

Answer:
Already discussed earlier, but here’s a recap —

  • Pass by value: Sends copy of data.
  • Pass by reference: Sends memory address.

Example (by reference):

void swap(int *a, int *b) {
   int temp = *a;
   *a = *b;
   *b = temp;
}

49. What are command line arguments in C?

Answer:
Command line arguments are values passed to main() from the command line.
Example:

int main(int argc, char *argv[]) {
   printf("%s", argv[1]);
   return 0;
}

50. What is volatile keyword in C?

Answer:
volatile tells the compiler that a variable’s value may change unexpectedly (like in hardware programs).
It prevents the compiler from optimizing that variable.

Example:

volatile int flag = 0;

51. What is pointer to pointer?

Answer:
A pointer to pointer means a variable that stores the address of another pointer.

Example:

int a = 10;
int *p = &a;
int **pp = &p;
printf("%d", **pp); // prints 10

52. What are bitwise operators in C?

Answer:
Bitwise operators perform operations on bits directly.
Operators:
& (AND), | (OR), ^ (XOR), ~ (NOT), << (Left shift), >> (Right shift).

Example:

int a=5,b=3;
printf("%d", a & b); // 1

53. What is the use of const keyword?

Answer:
const makes a variable’s value read-only, meaning it cannot be modified.
Example:

const int MAX = 100;

54. What is a dangling pointer?

Answer:
A dangling pointer occurs when the memory a pointer was pointing to is freed, but the pointer still exists.
It points to an invalid memory location.

Example:

int *ptr = (int*)malloc(sizeof(int));
free(ptr); // now ptr is dangling

55. What is the difference between stack and heap memory?

Answer:

StackHeap
Managed automatically.Managed manually using malloc/free.
Faster allocation.Slower but flexible.
Limited size.Large memory.

56. What is the difference between exit(0) and return 0?

Answer:

  • return 0 ends only the current function.
  • exit(0) terminates the entire program immediately.

57. What is inline function?

Answer:
An inline function tells the compiler to insert the function code directly instead of making a function call (for faster execution).

inline int square(int x){ return x*x; }

58. What are advantages of using C language?

Answer:

  • Fast execution speed.
  • Portable across platforms.
  • Easy to learn.
  • Rich library of functions.
  • Strong foundation for other languages.

59. What are disadvantages of C language?

Answer:

  • No built-in object-oriented features.
  • Manual memory management.
  • No exception handling.
  • Limited safety checks.

60. What are some real-world applications of C language?

Answer:

  • Operating systems (like Linux)
  • Database systems (like MySQL)
  • Compilers and interpreters
  • Embedded systems and firmware
  • Game engines

Conclusion

By now, you’ve learned not just the basic concepts of C, but also advanced topics that interviewers commonly ask even for fresher-level positions.

The best way to master C is to practice small programs daily, understand how memory works, and test your logic step by step.

Whether you’re applying for a software development job or preparing for college placements, these C interview questions (Part 2) will help you confidently face your interviewer.

Stay tuned for Part 3, where we’ll cover C programs and real interview coding problems with step-by-step explanations.


Leave a Comment