C Interview Questions and Answers

Last update: 26 Jan 2020, 43 Questions
C Interview Questions

C is a robust, powerful and fast general-purpose programming language. For fresher developers, C can be an excellent choice to start their programming journey. If you are preparing for the C language job interview, we have one of the biggest collection of C Interview Questions.

It is portable and available on all platforms. A lot of programming language such as PHP, Java, and JavaScript that made their entry after the C language has directly or indirectly borrowed features and syntax /features from it. C++ language is almost an extension of the C language. A lot of recent C programming interview questions were based on this information.

Our unique extensively researched C language interview questions are the best way to prepare for job interviews.

C Language
What is C language? C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, whilst a static kind machine prevents unintended operations.
Latest Version C18 and released in June 2018
Developed By Dennis Ritchie & Bell Labs
Designed By Dennis Ritchie

Most Frequently Asked C Interview Questions

Here in this article, we will be listing frequently asked C Interview Questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

1. How is a NULL pointer different from a Dangling pointer?
S.no NULL Pointer Dangling pointer
1. Indicates the pointer isn't pointing to a valid location Does not point to a correct place
2. Happens when memory pointed by it is deallocated Occurs when an object is removed or deleted
2. What are local static variables? How can you use them?

A local static variable gets defined in a specific block and is accessible locally inside that block only. However, because it is static, its value is persistent. Its lifetime does not end when a function call is declared. Instead, its lifetime extends throughout the program. Local static variables can be used for counting the number of times a particular function is called.

3. Differentiate abs() function from fabs() function.
S.no abs() fabs()
1. Used for integer values Used only for floating type
2. Prototype is under < stdlib.h > Prototype is under < math.h >
3. Returns absolute value of integer Returns absolute value of a floating-point
4. How is = symbol different from == symbol in C programming?
S.no “=” “==”
1. Assignment operator Comparison operator
2. Used to assign the value of right side to the variable on the left side Used to compare value on the left side with value on the right side
5. Why are algorithms important in C program?

It is a mandatory step to create an algorithm before writing any program in C. An algorithm gives step-by-step guidelines on how a solution can be achieved and also serves as a blueprint on how a program should start or end, including what processes and computations must be involved.

6. How is actual parameter different from the formal parameter?
S.no Actual Parameters Formal Parameters
1. Used in the function call Used in the function header
2. Pass actual values to the function definition Receive values passed to function
3. Can be constant or variable Treated as local variables
7. Why is C called "mother" language?

C is often referred to as the mother of all programming language because it is one of the most popular programming languages. Right from the time, it was developed, C has become the most widely used and preferred programming languages. Most of the compilers and kernels are written in C today.

8. What is an array? What the different types of arrays in C?

An Array is a group of elements having similar data types under a common name. In an array, the two-dimensional elements are stored in rows as per the memory locations. An element's array name represents the address of that element. It must be noted that the size of size is always constant and never a variable.

In C language, there are two types of arrays - Single Dimensional Array and Multi-Dimensional Array.

9. What do you mean by dynamic memory allocation in C? What functions are used?

It refers to the mechanism by which storage or memory gets allocated dynamically to variables during the runtime. This mechanism uses malloc(), and calloc() functions to allocate memory dynamically.

free() function is used to release dynamically allocated memory.

10. Compare interpreters and compilers.
S.no Interpreters Compilers
1. Deal with the way code gets executed Check the syntax of the program
2. Executes programs written in a source language Converts source language into object language.
3. Converts one line at a time Converts entire program in one time
11. Explain logical errors? Compare with syntax errors.
S.no Syntax errors Logical errors
1. Refers to an error in the sequence of characters Refers to an error in the algorithm
2. Use compiler to indicate errors The developer needs to detect an error on his own
3. Easier to identify errors Comparatively difficult
12. What are control structures? What are the different types?

These structures are statements that are used to control the flow and direction of the execution of a program in C. It brings together instructions and logical unit. Control structures have two main classes - conditionals and loops.

There are three different types of control structures are - Selection, Sequence, and Repetition.

13. What is C language & why it is used?

C is a robust, powerful and fast general-purpose programming language.C is a robust language with a rich set of built-in features and functions that can be used to build any complex web program. The C compiler has the potential of an assembly language and functionalities of a high-end language.

Why it is used?

Developers can use C language for developing system applications that are forming a huge portion of OS such as Windows, Linux, and UNIX. Most of the OS, C compiler and application programs in UNIX today are written in C.

14. Who developed C language and when?

Dennis Ritchie developed C language in 1972 at Bell Labs

15. Lists the benefits of C programming language?

One of the biggest benefits of learning the C language is that it is recognized worldwide and used in hundreds and thousands of applications worldwide, including scientific operating systems. This language combines the features of high end and basic languages. As a result, you can freely use it for starter-level programming as well as high-level programming such as scripting for complex applications.

17. Explain the term printf() and scanf() used in C language?
S.no printf() scanf()
1. Output function Input function
2. Prints character, float, integer, hexadecimal and octal, and values Reads string, character, and numeric data
3. Rarely needs pointer Always needs pointer
18. Explain the difference between the local variable and global variable in C?
S.no Local Variable Global Variable
1. Declared inside function Declared outside function
2. Accessed only by statements that are inside a function where they are declared Accessed by any statement throughout the program
3. Created when entering function block and gets destroyed when exits. Stays in existence throughout the when the application is executing
4. It is stored on the stack. Stored in a fixed location.
19. Explain the difference between call by value and call by reference in C language?
S.no Call By Value Call By Reference
1. Passing variable values when calling a function is called Call By Values Passing variable location when calling a function is called Call By Reference
2. Values of calling function variable to get copied into dummy variables Address of actual variables get copied into the dummy variables
3. Changes have no impact on values of actual variables Changes can manipulate real variables
4. Cannot alter the values of actual variables Possible to alter the values of variables
20. What do you mean by recursion in C?

Recursion is a function that calls itself. It is easy to write in the program, but it requires a lot of memory space and execution time. The advantage of using recursion is that developers can avoid unnecessary calling of functions by substituting with iteration.

21. What is pointer & why it is used?

The pointer is nothing but a variable that stores and points the address or location of a different variable. While a regular variable stores the value of a variable, a pointer variable stores the address or location of a variable.

Why it is used?

You can use pointers in a C program for getting the location of a variable, or for achieving pass by call reference. This is because pointers allow various functions to modify and share the local variables. You can also use a pointer for implementing “linked” data structures, such as lists and binary trees. Have you read our rest of the Interview Questions on C?

22. What is static memory allocation? Explain

It is the allocation of memory at the time of compilation before the associated program gets executed. Unlike dynamic or automatic memory allocation, where memory gets allocated as required at run time, this type of memory gets allocated by the compiler at the time of compilation.

23. Explain the difference between malloc() and calloc() in C?
S.no malloc() calloc()
1. Does not initialize allocated memory Fills allocated memory with zero bits.
2. Returns one single object Returns array of objects
24. What is structure in C language?

Structures are a collection of various data items of different data-types. Like an array, each member in a structure is located next to each other.

25. In C language can we compile a program without main() function?

Yes, it is possible to compile a program in C without the main function, but it will not get executed. This is because the execution starts only from the main function. This function is the entry point of every program in C. All pre-defined or user-defined functions are directly or indirectly called through the main function.

30. What do you mean by keywords in C?

Certain reserved words in C, which are known and understood by the compiler are called keywords. The meaning of these keywords is already known to the compiler. Keywords are always written in small case letters, and cannot be used as the names of variables as that may change their meaning. Some of the standard keywords are – auto, case, break, float, extern, etc.

31. Explain data types & how many data types supported by C?

In C language, data types mean an extensive system that is used for declaring the functions or variables of different types. The kind of a variable used will determine how much space it will occupy in the storage and how the stored bit pattern will be interpreted.

Some of basic data types in C are:
  • Int: For representing numbers (integer)
  • Float: For serving numbers with a fraction.
  • Double: For representing double-precision floating point value
  • Char: Represents single characters
  • Void: Shows particular purpose type without a value
32. How many types of errors are there in C language? Explain

This is a typical Embedded C Interview Questions. There are three error types in C language – Runtime, Compile and Logical.

Runtime errors may occur when the program is being run, usually due to illegal operations performed.

Compile errors occur during the compilation of the program. Compile errors are of two types- Syntax and Semantic.

Logical errors occur in the output due to errors in the logic applied in the C program.

33. Explain the difference between ++u and u++?
S.no ++u u++
1. Called prefix increment. Called postfix increment
2. Increment happens on the variable first. Increment happens after variable’s value is used.
34. What is modifier & how many types of modifiers available in C?

The modifier is a prefix for a basic data type that is used for indicating the modification required in the storage space allocated to the variable. A total of five modifiers are available in C programming – Short, Long, Signed, Unsigned, and long. This information is critical for Embedded C Interview Questions.

37. What is the purpose of main( ) in C language?

The main() function is the entry point in C programming language. This function is called by OS the moment a user runs a program. The purpose of this function is crucial because the execution of a C program starts from here. Without the main() function, you cannot execute a program.

38. What are the string functions? List some string functions available in C.

Strings are an array of characters that end with a null character (‘\0’). The presence of null character specifies the end of a string. Remember, strings should always be enclosed by double quotes.

Most used functions in the string library are listed below:
  • strlen
  • strcat
  • strchr
  • strcpy
  • strncat
  • strcmp etc
39. Explain the difference between structs and unions in C?
S.no Structs Union
1. Defines a structure Defines a union
2. All members get allocated memory Compiler allocates memory to largest members
3. Possible to initialize one or more members at once Gets initialized by the value of the type of the first member
4. Possible to access individual member any time Can only access one member at a time.
40. Explain the difference between #include "..." and #include <...> in C?
S.no #include< > #include" "
1. Compiler searches header files in the standard directory Compiler searches header files in the current directory
2. Used for including standard library header files. Used for including programmer-defined header files.
41. How we can insert comments in a C program?

Comments are an amazing way to insert remarks in a program that can serve as a reminder of what a given program is all about. Get more knowledge of this topic if you are preparing for Interview Questions on C. You can also add a description of why a certain function or code was placed in the first place.

Comments begin with /* and end by */ characters. Comments can be single or several lines and can be placed anywhere in the C program.

C is a robust language with a rich set of built-in features and functions that can be used to build any complex web program. The C compiler has the potential of an assembly language and functionalities of a high-end language. The programs written in this language are robust and efficient, mainly due to its unique data type and strong operators. Much faster than BASIC, it is one of the most widely used languages in OS and embedded system development. On our website, we have provided potential C interview questions.

As a programming language, C is one of the best languages known due to its simplicity of syntax coupled with fantastic functionality. Despite being 40 years old, C language is still trendy. One of the biggest reasons is that the source code written in C works in another OS without a single change. This language is a perfect mix of ease of use with robust features, which makes it an ideal language to be taught to even fresher developers, with an aim to introduce the programming world to them. We can help you prepare for C Interview Questions and Answers by educating you in-depth about this language.

Development History

Initially developed during around 1972 - 1973 at Bell Labs by Dennis Ritchie, mainly for writing OS like UNIX. Some people call it a successor of the B language that was written in the early 1970s. This information is mostly asked during C interview questions.

Latest Version

Many candidates were asked about the features in the latest versions during about their C Programming Interview Questions. C18‎ is the latest stable version, which was released on June 2018.

About Best Interview Question
Best Interview Question
Technical Consultant

With our 10+ experience in PHP, MySQL, React, Python & more our technical consulting firm has received the privilege of working with top projects, 100 and still counting. Our team of 25+ is skilled in distinct programming languages such as Python, Java, React.js, Angular, Node.js, PHP, HTML, CSS, Designing, iOS and Android apps, Database, .net, QA, Digital Marketing and Govt. jobs, etc. We are helping 10+ companies in solving their technical problems. When not found coding, our technical consultants can be seen helping out others.