56 Basic C Programming Questions and Answers for Interviews

Here’s the list of basic yet important C programming questions. Most of these questions get repeated in interviews. Go through these questions and comment if you have any problem in any one of these. We can discuss it.

  1. Write a C program to swap two variables without using a temporary variable.
  2. What is the 8 queens problem? Write a C program to solve it?
  3. Write a C program to print a square matrix helically.
  4. Write a C program to reverse a string.
  5. Write a C program to reverse the words in a sentence in place.
  6. Write a C program generate permutations.
  7. Write a C program for calculating the factorial of a number.
  8. Write a C program to calculate pow(x,n)?
  9. Write a C program which does wildcard pattern matching algorithm.
  10. How do you calculate the maximum subarray of a list of numbers?
  11. How to generate fibonacci numbers? How to find out if a given number is a fibonacci number or not? Write C programs to do both.
  12. Solve the Rat In A Maze problem using backtracking.
  13. What Little-Endian and Big-Endian? How can I determine whether a machine’s byte order is big-endian or little endian? How can we convert from one to another?
  14. Write C code to solve the Tower of Hanoi problem.
  15. Write C code to return a string from a function.
  16. Write a C program which produces its own source code as its output.
  17. Write a C progam to convert from decimal to any base (binary, hex, oct etc…).
  18. Write C code to check if an integer is a power of 2 or not in a single line?
  19. Write a C program to find the GCD of two numbers.
  20. Write code to remove duplicates in a sorted array.
  21. Find the maximum of three integers using the ternary operator.
  22. How do you initialize a pointer inside a function?
  23. Write C code to dynamically allocate one, two and three dimensional arrays (using malloc()).
  24. How would you find the size of structure without using sizeof()?
  25. Write a C program to multiply two matrices.
  26. Write a C program to check for palindromes.
  27. Write a C program to convert a decimal number into a binary number.
  28. Write C code to implement the Binary Search algorithm.
  29. Write code to evaluate a polynomial.
  30. Write code to add two polynomials.
  31. Write a program to add two long positive numbers (each represented by linked lists).
  32. How do you compare floating point numbers?
  33. What’s a good way to implement complex numbers in C?
  34. How can I display a percentage-done indication on the screen?
  35. Write a program to check if a given year is a leap year or not?
  36. Is there something we can do in C but not in C++?
  37. How to swap the two nibbles in a byte ?
  38. How to scan a string till we hit a new line using scanf()?
  39. Write pseudocode to compare versions (like 115.10.1 vs 115.11.5).
  40. How do you get the line numbers in C?
  41. How to fast multiply a number by 7?
  42. Write a simple piece of code to split a string at equal intervals.
  43. Is there a way to multiply matrices in lesser than o(n^3) time complexity?
  44. How do you find out if a machine is 32 bit or 64 bit?
  45. Write a program to have the output go two places at once (to the screen and to a file also).
  46. Write code to round numbers.
  47. How can we sum the digits of a given number in single statement?
  48. Given two strings A and B, how would you find out if the characters in B were a subset of the characters in A?
  49. Write a program to merge two arrays in sorted order, so that if an integer is in both the arrays, it gets added into the final array only once.
  50. Write a program to check if the stack grows up or down.
  51. How to add two numbers without using the plus operator?
  52. How to generate prime numbers? How to generate the next prime after a given prime?
  53. Write a program to print numbers from 1 to 100 without using loops.
  54. Write your own trim() or squeeze() function to remove the spaces from a string.
  55. Write your own random number generator function in C.
  56. Write your own sqrt() function in C.

Related posts:

  1. 27 Important Tree Data Structure Interview Questions and Answers
  2. 19 Important Linked List Interview Questions and Answers
  3. 21 Important C Pointers Interview Questions and Answers
  4. Using stringstream in C++
  5. How to know IMEI number of your cellphone

Article by Harsh

Harsh is an avid Blogger who blogs at Harsh Tech Talk. He writes about Blogging, Facebook, Twitter, technology and tips and tricks. By profession he is a software engineer working at Oracle, Bangalore. He is a big music freak.

  • http://www.cprogramming.tk pankaj

    Nice set of questions.Really helped me for preparing my technical interview

  • http://www.digitalfacts.net Sunil Kumar

    Great list…..

  • Prashisndira

    superb questions

  • http://www.techiespider.com manoj

    good list

  • Mukmipkel

    How to generate prime numbers? How to generate the next prime after a given prime?

  • Monica Medisetti

    how to generate fibonacci nos and how to check given no is fibonacci or not?

    • Uma999 Chandusantu

      Adding first 2 numbers,den v geting 3dr no. den dis z cald fibonacci

  • R.manivannan

    can anyone please send me the answer for this questions…..
    Mail Id:rmanivannanit@gmail.com