JOBSEEKER?

C Interview Questions

Practice for C interviews by solving TestDome questions. Our interview questions are used by more than 7,000 companies and 450,000 individual test takers.

Jobseekers: Certify Your Knowledge

Take a Certification Test

Companies: Use Our Tests for Screening

Buy a Pack Of Candidates

Need to practice your C programming skills for an upcoming job interview? Try solving these C interview questions that test knowledge of C programming concepts such as arrays, recursion, pointers, memory management, and other skills. We’ll provide feedback on your answers, and you can use a hint if you get stuck.

These C interview questions are examples of real tasks used by employers to screen job candidates such as C developers, software engineers, back-end developers, and others that require knowledge of the C programming language.

1. Words

C Algorithmic thinking Sorting Public
   
Easy  

Implement function sort_words that sorts an array of words that contain lowercase characters from english alphabet, in descending order, and is efficient with respect to time used.

For example, the array { "cherry", "orange", "apple" } should, after sorting, become { "orange", "cherry", "apple" }.


2. Binary Search Tree

C Algorithmic thinking Recursion Tree Public
   
Easy  

Binary search tree (BST) is a binary tree where the value of each node is larger or equal to the values iA three-node binary tree.n all the nodes in that node's left subtree and smaller than the values in all the nodes in that node's right subtree.

Write a function that, efficiently with respect to time used, returns 1 if a given binary search tree contains a given value, else 0.

For example, for the following tree:

  • n1 (Value: 1, Left: null, Right: null)
  • n2 (Value: 2, Left: n1, Right: n3)
  • n3 (Value: 3, Left: null, Right: null)

Call to contains(&n2, 3) should return 1 since a tree with root at n2 contains number 3.


3. Inspect Bits

C Bit manipulation Public
   
Easy  

Implement the inspect_bits function that checks if given number contains 2 or more consecutive ones in its binary representation. If it does, the function should return 1. Otherwise, it should return 0.

For example, inspect_bits(13) should return 1 as it contains 2 consecutive ones in its binary representation (1101).


4. Quadratic Equation

C Arithmetic Public
   
Easy 

Implement the function find_roots to find the roots of the quadratic equation: ax2 + bx + c = 0. If the equation has only one solution, the function should return that solution as both roots. The equation will always have at least one solution.

The roots of the quadratic equation can be found with the following formula: A quadratic equation.

For example, the roots of the equation 2x2 + 10x + 8 = 0 are -1 and -4.


5. Watched Videos

C Arrays Pointers Public
   
Easy  

Implement the count_views function. It accepts an array of pointers to the Viewer struct, the size of the array, and the character array with the video name. It should return the number of Viewers who have watched a Video with the name video_name.

For example,

Video videos[] = { {.name = "Soccer", .unique_views = 500},
                   {.name = "Basketball", .unique_views = 1000} };
Viewer viewer = {.username = "Dave", .watched_videos = videos,
                 .watched_videos_size = 2};    
Viewer *viewers[] = { &viewer };

calling count_views(viewers, 1, "Soccer") should return 1.


6. User Info

C Data structure alignment Memory management New Public
   
Hard  

Consider the struct UserInfo, which is used in a performance critical sub-system.

Currently, on a system where an int takes 4 bytes, char takes 1 byte and long long takes 8 bytes, the struct takes 40 bytes of space. Rearrange the struct, without removing, renaming, or changing the type of the members, so that it uses less memory. The code uses pointers to struct members, so struct should be properly aligned.


If you feel ready, take one of our timed public C Interview Questions tests:
C

C Online Test (Easy / Hard)

Embedded Systems

Embedded Systems and C Online Test (Easy)

Not exactly what you are looking for? Go to our For Jobseekers section.
Dashboard Start Trial Sign In Home Tour Tests Questions Pricing For Jobseekers