What types of questions will you encounter during a C interview? It really depends. There are two major types of questions an interviewer will ask:

  1. Questions about your foundational knowledge of C. What is it? What does it do? Why would you use it? What are its advantages?
  2. Questions about syntax and functions. How in-depth is your working knowledge of C? Can you program a basic application right now?
Two people talking in office setting

Many code interviewers will ask you not only about your general knowledge of C, but also perform a code interview — they will ask you to program for them. Brushing up on C programming projects is the best way to ensure that you’re up to the task.

Now, let’s take a look at some of the most common C interview questions.

1. Why would you use the C programming language?

There are five important aspects of C programming: speed, portability, flexibility, modularity, and extensibility. When an interviewer asks this question, they are generally looking for a combination of the above. Stress that the C programming language is close to machine code, that it is highly efficient, and that it allows for greater levels of control.

C Programming For Beginners

Last Updated August 2019

  • 76 lectures
  • All Levels
4.4 (4,119)

Learn C in ten easy steps on Windows, Mac OS X or Linux | By Huw Collingbourne

Explore Course

2. What is the main difference between C and C++?

Though C and C++ are vastly different, the major difference is that C is a procedural language whereas C++ is an object-oriented language.

3. When would you use C versus Java?

Java is a more abstract and easy-to-use language, but that level of abstraction comes at a cost. C allows for more efficient builds and more direct control over a machine. Because Java is a common programming language, many interviewers may ask you what the differences between them are, and what the use cases are for C instead. Remember that C is more lightweight and gives more granular access to things like memory allocation.

4. Name the five basic data types associated with C.

The five basic types are int, float, double, char, and void. They would be declared as such:

int intNum = 1;
	int floatNum = 2.2;
	double floatNum = 2.34;
	char stringChar = “Hello”;
	void function ();

5. What is the printf() function and its usage?

The printf() function is the most common function used for printing data to the user’s console. You would use it like so:

printf(“Hello World!”);

This will give the following result:

Hello World!

6. How do you increment or decrement in C?

Incrementing is done like this:


It means to increment a number by one.

Decrementing is done like this:


It means to decrement a number by one.

7. What are i++ or i– examples of?

In addition to being arithmetic, incrementing, and decrementing functions, these are examples of unary operations.

8. Void and return are examples of what in C?

Void and return are examples of “reserved words” in C. They cannot be used for variable names. They are used as follows:

void function();
	return 0;

There are a number of reserved words in C. If you attempt to use these out of traditional syntax, you will get a syntax error.

9. What is a dangling pointer in C?

A dangling pointer occurs when you delete a variable but a pointer to the memory address remains. Dangling pointers should not be referred to. 

10. How would you get data from a user?

To get data from a user, you would use the scanf() function. In using it, you would also indicate the type of data that you would want from the user. If you wanted a string, you would:

scanf(“%s”, stringUser);

This would read whatever the user typed into a string.

11. What is the difference between a++ and ++a?

Placement of the operators controls whether the variable is incremented before or after the operation. 

Both operations are going to be faster than a=a+1 because they are unary operations that are inherently faster. 

12. What is the difference between = and ==?

A single = sign sets the variable to the left of the value on the right. A double == sign compares the value on the left to the value on the right. For example:

intNum = 3;

This would set the intNum variable to 3.


This would start an if/else code block if intNum already equaled 3.

13. What would the value be of the expression 3 [“abcdef”]?

The value of this expression would be “d.” Keep in mind that strings are treated as arrays and also that arrays always start at 0. 

If asked to quantify a string (refer to a single specific location of a string), always think about that string as individual characters of an array.

14. How would you comment code in C?

There are two ways to comment code in C. First, you can comment code as a single line:

//this is a single line comment

You can also comment code as multiple lines:

/* This is a multiple
	line code comment */

You should use both frequently to comment on code.

15. Can you convert a string to a number?

In C, you can convert a string to a number using the function atoi() like this:

int atoi(myString);

It is fairly easy to convert a string to a number, but doing so strips out any characters that can’t be numbers.

16. What is a global int?

A global int is an int that is referable from anywhere. C is a scoped language, meaning that most variables are “local” in scope and can only be referred to from a given function. A global variable can be referred to from anywhere.

17. Why should you use n++ over n+1?

n++ is a unary operation that will execute faster. For most applications, this won’t matter. But some people find that over an extensive number of applications, there is a notable difference. For readability, n+1 often reads better.

18. When should you use an if/else statement? What is the syntax?

You use if/else statements for logical statements in which a code block will function if it meets a certain logical operation, but will not function if it does not. 

if(intNum==1) {
	} else {

19. How do you program a for loop? What is the syntax?

You use a for loop when code must be iterated through a certain number of times.

for(int i = 1; int < 11; i++) {

20. How do you program a switch case? When would you use it?

A switch case switches through different “cases” of code; it’s used when there are multiple paths that the code could take.

switch(intCase) {
		case 0: printf(“The number is 0.”); break;
		case 1: printf(“The number is 1.”); break;

21. What is a memory leak?

Memory leaks occur as an application uses up progressively more memory during its run-time because it is not properly managing its memory usage. Memory leaks most commonly occur when stored data is not destroyed after use.

22. How do you unallocate memory?

In C, you can manually unallocate memory using the free() command. 


You must only do this once finished with using this variable.

23. What’s the difference between #include “…” and #include <…>?

When you include a file header, you can either:


Or you can

#include “filename”;

While they may seem identical, they’re not. <> works for standard header files; the file will look within predefined libraries first. “” starts searching from the current directory and is usually used for user-defined libraries.

24. What is a dangling pointer?

A dangling pointer refers to a pointer that is already freed. A freed pointer variable should no longer be referenced or manipulated:

	intExample = 3;

This would be an error because you’ve written to a pointer that is already freed.

25. What’s the difference between “abc” and ‘abc’?

Double quotes refer to strings whereas single-quotes refer to characters. When doing something like printf, it’s important to always use double quotes:

printf(“Hello, World!”);

26. Where is the error in this code?

int main() {
		printf(“Hello World!”)

This is the most common type of programming error. It’s a missing semicolon.

27. What are syntax errors?

Syntax errors are errors in the “grammar” or structure of a programming language that make it impossible for the compiler to read. 

28. What are static functions? 

The C language has scope. Static functions are only visible to functions that are in the same file. These functions may work in a specific module but not be referenced outside of it.

29. What variable name is correct for an int? Choices: int i, int integerI, int int_num.

They are all correct. You can name variables anything you want, but keep in mind that referring to them is case-sensitive. Variables are frequently named with two different types of convention:




30. What’s the difference between an int, float, and double?

An int is an integer which can be either signed or unsigned and must be a whole number. A float can have up to 32 bits of precision. A double can have up to 64 bits of precision.

31. How can you improve the readability of your source code?

There are two major ways to improve readability of source code: commenting and whitespace. Commenting refers to leaving comments in the source code, while whitespace refers to controlling how the code looks and feels by using enters, spaces, and tabs.

Properly formatted code:

int main() {
		//Print a line that says “Hello World!”;
		printf(“Hello World!”);

Improperly formatted code:

int main(){printf(“Hello World!”);}

Importantly, improperly formatted code will usually still compile. It just won’t be readable.

32. What is “call by reference”?

You can refer to functions either by value or by reference. When you refer by reference, you include pointers in the function’s parameters, like so:

function myFunction (int* x, int* y);

When you refer by value, you include values in the function’s parameters:

function myFunction (int x, int y);

For the most part, functions are going to be called by value rather than reference. Both functions will be able to perform the same way.

33. Can C run on all operating systems?

C is a very broad language that can run on nearly any operating system, which is why it’s considered to be one of the most portable and versatile. It cannot run on all operating systems, but it can run on all major ones. 

34. What are printf and scanf used for?

The printf() function prints to the console, while the scanf() function collects information from a user. 

35. What are formal parameters?

Formal parameters are the parameters that used internally in a function. A function is often passed parameters from outside, but these are the “actual” parameters. In this example:

int myNumber(int number) {

	void main() {
		int numberOne = 3;

36. How do you make a basic function call?

A function is a basic block of code — and one of the most fundamental parts of programming in C. To call a function, you call the function name and pass along its parameters:

functionName (parameter1, parameter2…);

A function can have no parameters or many parameters, and it may either return a value or be void.

37. What are the most popular library functions?

The most common library functions include printf(), scanf(), fprintf(), concat(), and strlen(). An interviewer may be ask you to describe what these library functions do. This is what they do:

38. What do you need to declare with a variable?

Variables declared need to have a type and a name, but not necessarily a value. You can declare a variable like so:

int intNum;
	intNum = 1;

Or you can declare it and set it at the same time:

int intNum=1;

39. What is a local variable?

A local variable is a variable that is within a single function’s scope. This variable is accessible within the function but not outside of the function.

40. What are data structures?

Data structures are relationships formed between discrete pieces of data. A data tree is an example through which data relates to other pieces of data, and through which there is a hierarchy of data. Data structures are not inherent in C but can be developed through C. 

41. Describe a pointer and its usage

A pointer is an address to a memory location. It can be used to allocate and deallocate memory, as it always points to the area that stores a value. Importantly, a pointer does not lead to the value of a variable itself, but rather to where that variable is. A null pointer is a pointer that doesn’t lead anywhere.

42. What are command line arguments?

In C, along with other command line applications, certain arguments can pass to the program as it runs. These arguments will work in the program upon initialization and can control the program’s flow. These arguments pass to the main function and therefore should be declared in the main function.

43. How are parameters passed to a function?

Parameters are passed to a function when the function is called. Let’s look at a function that has two parameters: numOne and numTwo.

void myFunction (int numOne, int NumTwo) {

This function doesn’t do anything yet, but it is passed two ints. When called, it would be called like so:

myFunction (1,2);

44. What is the difference between declaring and defining a variable?

When a variable is declared, it is declared with a type and a name. You would declare a string named “stringHello” like this:

string stringHello;

Once that string has been declared, it can then be defined. Defining a variable means setting its value:

stringHello = “Hello there!”;

45. What is an enum?

An enum is an enumerated value or a user-defined value. It is a variable that can only be a single set of options listed by the programmer. You use enums when you want a variable to only have certain supported values, such as a variable that only has 1, 2, and 3.

46. What is a macro in C?

A macro is a named fragment of code. If you wanted, for instance, to define the macro “PI” you would do as follows:

#define PI 3.1415

From then on, any reference to PI would be 3.1415. Macros can be quite powerful, but they can also be too powerful; if you aren’t careful, you can break your code. This is because a macro can contain larger elements of code, and it can be difficult to know what a macro is doing if reading.

47. Should you use tabs or spaces in C?

Once compiled, there is no difference in tabs or spaces in C. Tabs and spaces are purely up to the programmer to decide on, depending on what they find to be most efficient and easiest to read. However, programmers should never switch between tabs and spaces, because this can make their code look uneven depending on the system and editor. 

48. What does “commenting out” refer to?

Commenting out occurs when a programmer “comments out” code to erase it from the block. The following code has been partially commented out:

int main() {

The above code will only print “Hello.” It won’t print “World.” The “World” has been commented out. Programmers will frequently comment out their code as a part of the debugging process so as to see which line has errors in it. This can help them determine which areas of their code aren’t working, though the compiler may also help narrow it down.

49. What is a stack in C?

A stack is a type of data structure, in which “Last In First Out” rules apply. Essentially, it is a “stack” of data, one on top of the other, much like an array. The difference between a stack and an array is the way that data is stored; data is pushed to the top of the stack each time. Stacks are also dynamic and can be added to, whereas an array has a fixed size. 

50. What is “spaghetti code”?

Spaghetti code is code that’s unstructured, usually referring to code developed by an amateur. Spaghetti code is messy and often cannot be followed; new programmers will throw code in anywhere and hope that it works. Spaghetti code makes code very difficult to read. 

Because C is a procedural language, programmers should try their best to order the code intuitively and to comment out each independent section of their code. Object-oriented languages tend to be easier to organize out-of-the-box because everything is already classed by object.

51. Which of the following operators is incorrect? >=, ==, <=, <>

The <> operator is incorrect. In some languages, “<>” means “not equal to.” In C, that is !=, such as:

if(1 != 2) {
		printf(“All is correct!”);

Operators compare different values, both of specific items (such as above where 1 compares to 2) and for variables.

if(stringDebug == 1) {
		printf(“You are in debug mode.”);

Preparing for a C interview

Many C questions and answers are a matter of perspective. When talking to an interviewer, be as specific as possible. If they are asking you, for instance, about the “most powerful” C function, that is something that is subjective; what they are looking for is how you describe your answer and how well you know what the functions do.

The C programming language is complex. Because it is so much closer to machine-level code than many modern, abstract languages, there’s a lot more that can go wrong — but there’s also significantly more power and flexibility. When preparing for a C interview, the best thing you can do is practice your code, understand why you’re doing what you’re doing, and read C questions and answers online.

Page Last Updated: October 2021

Top courses in C (programming language)

C Programming For Beginners - Master the C Language
Tim Buchalka's Learn Programming Academy, Jason Fedin
4.3 (28,991)
Advanced C Programming Course
Tim Buchalka's Learn Programming Academy, Jason Fedin
4.4 (3,136)
C Programming Bootcamp - The Complete C Language Course
Vlad Budnitski
4.5 (5,293)
Linked Lists with C
Portfolio Courses
4.8 (53)
Learn C++ Programming by Making Games
Serge Lansiquot
4.4 (501)
Advanced C Programming: Pointers
Huw Collingbourne
4.6 (2,840)

More C (programming language) Courses

C (programming language) students also learn

Empower your team. Lead the industry.

Get a subscription to a library of online courses and digital learning tools for your organization with Udemy Business.

Request a demo