Top 50 C Programming Interview Questions and Answers
Top 50 C Programming Interview Questions and Answers
C C Basics C Data Types C Operators C Input and Output C Control Flow C Functions C Arrays CS
1. For Freshers
2. For Experienced
In this article, you will get the frequently and most asked C programming
interview questions and answers at the fresher and experienced levels. So,
let us start with Questions for freshers.
We usetocookies
writetooperating systems
ensure you have and menu-driven
the best browsing experience on ourconsumer billing systems.
website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Got It !
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 1/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Each variable in C has an associated data type. Each data type requires
different amounts of memory and has some specific operations which can be
performed over it. It specifies the type of data that the variable can store like
integer, character, floating, double, etc. In C data types are broadly classified
into 4 categories:
Primitive data types: Primitive data types can be further classified into
integer, and floating data types.
Void Types: Void data types come under primitive data types.
Void data types provide no result to their caller and have no
value associated with them.
User Defined data types: These data types are defined by the user to
make the program more readable.
Derived data types: Data types that are derived from primitive or built-in
data types.
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 2/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Data Types in C
https://www.geeksforgeeks.org/c-interview-questions/ 3/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Processor in C
https://www.geeksforgeeks.org/c-interview-questions/ 4/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Output
calloc() and malloc() library functions are used to allocate dynamic memory.
Dynamic memory is the memory that is allocated during the runtime of the
program from the heap segment. “stdlib.h” is the header file that is used to
facilitate dynamic memory allocation in the C Programming language.
https://www.geeksforgeeks.org/c-interview-questions/ 5/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
https://www.geeksforgeeks.org/c-interview-questions/ 6/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
// Driver code
int main()
{
char res[20];
float a = 32.23;
sprintf(res, "%f", a);
printf("\nThe string for the num is %s", res);
return 0;
}
Output
12. What is the difference between the local and global variables in C?
Local variables are declared inside a block or function but global variables
are declared outside the block or function to be accessed globally.
By default,
We use cookies to ensure variables
you have thestore a garbage
best browsing experienceBy
ondefault value
our website. of the global value is
By using
our site, you acknowledge thatvalue. zero.
you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 7/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Pointers are used to store the address of the variable or a memory location.
Pointer can also be used to refer to another pointer function. The main
purpose of the pointer is to save memory space and increase execution time.
Uses of pointers are:
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 8/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Working of Pointer
Syntax:
Here,
Example:
15. What are loops and how can we create an infinite loop in C?
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 9/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Types of Loops
// Driver code
int main()
{
for (;;) {
printf("Infinite-loop\n");
}
while (1) {
printf("Infinite-loop\n");
}
do {
printf("Infinite-loop\n");
} while (1);
return 0;
}
16. What is the difference between type casting and type conversion?
We use cookies to ensure you have the best browsing experience on our website. By using
The
our site, you data typethat
acknowledge is you
converted
have readtoandanother data
understood our type The
Cookie Policy data type is converted
& Privacy
by a programmer with Policythe help of a casting to another data by a
https://www.geeksforgeeks.org/c-interview-questions/ 10/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
operator. compiler.
In Type casting in order to cast the data type In type conversion, there is
into another data type, a caste operator is no need for a casting
needed operator.
Type casting takes place during the program Type conversion is done at
design by the programmer. compile time.
Syntax:
Syntax:
int a = 20; float b; b = a; // a
destination_data_type = (target_data_type)
= 20.0000
variable_to_be_converted;
For more information, refer to the article – Type Casting and Type
Conversion.
https://www.geeksforgeeks.org/c-interview-questions/ 11/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
The function is a block of code that is used to perform a task multiple times
rather than writing it out multiple times in our program. Functions avoid
repetition of code and increase the readability of the program. Modifying a
program becomes easier with the help of function and hence reduces the
chances of error. There are two types of functions:
Macro Function
We use cookies to ensure you have the best browsing experience on ourCode
website. By using
length remains unaffected
our site, you Code length
acknowledge thatisyou
increased
have readusing macro. our Cookie Policy & Privacy
and understood using function.
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 12/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Macro Function
The macro name is replaced by the macro Transfer of control takes place
value before compilation. during the function call.
https://www.geeksforgeeks.org/c-interview-questions/ 13/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
keywords. Some examples of reserved keywords are auto, else, if, long, int,
switch, typedef, etc.
Example:
struct student
{
char name[20];
int roll_no;
char address[20];
char branch[20];
};
// Driver code
int main()
{
struct student obj;
We use cookies to ensure you have the best browsing experience on our website. By using
strcpy(obj.name,
our site, you acknowledge that you have read "Kamlesh_Joshi");
and understood our Cookie Policy & Privacy
obj.roll_no = 27;
Policy
strcpy(obj.address, "Haldwani");
https://www.geeksforgeeks.org/c-interview-questions/ 14/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
strcpy(obj.branch, "Computer Science And Engineering");
return 0;
}
Output
Name: Kamlesh_Joshi
Roll_No: 27
Address: Haldwani
Branch: Computer Science And Engineering
A union is a user-defined data type that allows users to store multiple types
of data in a single unit. However, a union does not occupy the sum of the
memory of all members. It holds the memory of the largest member only.
Since the union allocates one common space for all the members we can
access only a single variable at a time. The union can be useful in many
situations where we want to use the same memory for two or more
members.
Syntax:
union name_of_union
{
data_type name;
data_type name;
};
We useFor more
cookies information,
to ensure you have therefer article –onUnion
to theexperience
best browsing in CBy using
our website.
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
24. What is an r-value and Policyvalue?
https://www.geeksforgeeks.org/c-interview-questions/ 15/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Example:
25. What is the difference between call by value and call by reference?
Dummy variables copy the value of each Dummy variables copy the address
variable in the function call. of actual variables.
For more information, refer to the article – Call by Value and Call by
We useReference
cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
26. What is the sleep() function? Policy
https://www.geeksforgeeks.org/c-interview-questions/ 16/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
sleep() function in C allows the users to wait for a current thread for a given
amount of time. sleep() function will sleep the present executable for the
given amount of time by the thread but other operations of the CPU will
function properly. sleep() function returns 0 if the requested time has
elapsed.
int main()
{
enum week day;
day = Wed;
printf("%d", day);
return 0;
}
Output
In the above example, we declared “day” as the variable, and the value of
“Wed” is allocated to day, which is 2. So as a result, 2 is printed.
https://www.geeksforgeeks.org/c-interview-questions/ 17/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
29. Write a C program to print the Fibonacci series using recursion and
without using recursion.
Fibonacci Numbers
printf(
"Fibonacci Series with the help of Recursion:\n");
Fibonacci(num - 2, 0, 1, 0);
first = second;
second = third;
}
return 0;
}
Output:
Please Enter number of Elements: 5
Fibonacci Series with the help of Recursion:
0 1 1 2 3
Fibonacci Series without Using Recursion:
0 1 1 2 3
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 19/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
// C program to check if a
// number is prime
#include <math.h>
#include <stdio.h>
// Driver code
int main()
{
int num;
int check = 1;
if (num <= 1) {
check = 0;
}
if (check == 1) {
printf("%d is a prime number", num);
}
else {
printf("%d is not a prime number", num);
}
We use cookies to ensure you have the best browsing experience on our website. By using
return 0;
our site, you acknowledge
}
that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 20/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Source code can be easily modified and Object code cannot be modified and
contains less number of statements contains more statements than
than object code. source code.
Source code can be changed over time Object code can be modified and is
and is not system specific. system specific.
Source code is less close to the machine Object code is more close to the
and is input to the compiler or any other machine and is the output of the
translator. compiler or any other translator.
https://www.geeksforgeeks.org/c-interview-questions/ 21/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
For more information, refer to the article – Static and Dynamic Memory
Allocation in C
// Driver code
int main()
{
int num = 20;
printf("Value of num before passing is: %d\n", num);
return 0;
}
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 22/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Arguments that are passed to the main() function of the program in the
command-line shell of the operating system are known as command-line
arguments.
Syntax:
We use cookies to ensure you have the best browsing experience on our website. By using
37. Write a program to print “Hello-World” without using a semicolon.
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 23/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
// Driver code
int main()
{
// This will print the hello-world
// on the screen without giving any error
if (printf(“Hello - World”)) {
}
return 0;
}
int main()
{
// you
We use cookies to ensure Variable
have the declaration
best browsing experience on our website. By using
int var1 = 50;
our site, you acknowledge that you have
int var2 = 60;
read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 24/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
printf(
"Values before swap are var1 = %d and var2 = %d\n",
var1, var2);
return 0;
}
Output
https://www.geeksforgeeks.org/c-interview-questions/ 25/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
// Driver code
int main()
{
Palindrome("abba");
return 0;
}
Output
abba is a Palindrome
Modifiers are keywords that are used to change the meaning of basic data
types in C language. They specify the amount of memory that is to be
allocated to the variable. There are five data type modifiers in the C
programming language:
long
short
signed
unsigned
long long
41. Write a program to print the factorial of a given number with the help
of recursion.
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 26/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Factorial of a Number
// Driver code
int main()
{
int num = 5;
printf("Factorial of %d is %d", num, factorial(num));
return 0;
}
Output
Factorial of 5 is 120
// Driver code
int main()
{
int n;
int var = n;
We use cookies to ensure
intyou have= the
sum 0; best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy the order of
// Loop to calculate
// the given number
https://www.geeksforgeeks.org/c-interview-questions/ 27/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
while (n > 0) {
int rem = n % 10;
sum = (sum) + (rem * rem * rem);
n = n / 10;
}
Output
Enter Number
0 is an Armstrong number
// Driver code
int main()
{
int n, rev = 0;
printf("Number
We use cookies to ensure you have the bestAfter reversing
browsing experiencedigits is: %d",
on our website. rev);
By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
return 0;
} Policy
https://www.geeksforgeeks.org/c-interview-questions/ 28/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Output:
The extern keyword is used to extend the visibility of the C variables and
functions in the C language. Extern is the short name for external. It is used
when a particular file needs to access a variable from any other file. Extern
keyword increases the redundancy and variables with extern keyword are
only declared not defined. By default functions are visible throughout the
program, so there is no need to declare or define extern functions.
printf() function is used to print the value which is passed as the parameter
to it on the console screen.
Syntax:
print(“%X”,variable_of_X_type);
scanf() method, reads the values from the console as per the data type
specified.
Syntax:
scanf(“%X”,&variable_of_X_type);
In C format specifiers are used to tell the compiler what type of data will be
We use cookies toinensure
present the you have the during
variable best browsing
inputexperience
usingon our website.
scanf() By using using print().
or output
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
%c: Character format specifierPolicy used to display and scan character.
https://www.geeksforgeeks.org/c-interview-questions/ 29/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
%d, %i: Signed Integer format specifier used to print or scan an integer
value.
%f, %e, or %E: Floating-point format specifiers are used for printing or
scanning float values.
%s: This format specifier is used for String printing.
%p: This format specifier is used for Address Printing.
Near Pointers: Near pointers are used to store 16-bit addresses only.
Using the near pointer, we can not store the address with a size greater
than 16 bits.
Far Pointers: A far pointer is a pointer of 32 bits size. However,
information outside the computer’s memory from the current segment can
also be accessed.
Huge Pointers: Huge pointer is typically considered a pointer of 32 bits
size. But bits located outside or stored outside the segments can also be
accessed.
File Operations in C
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
48. Write a Program to check whether a linked list is circular or not.
https://www.geeksforgeeks.org/c-interview-questions/ 30/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
int main()
{
return 0;
}
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 31/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
/* you
We use cookies to ensure tail
havepoints
the bestto the last
browsing result
experience node
on our */ By using
website.
struct Node* tail = &dummy;
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
/* so tail->next Policy
is the place to add new
https://www.geeksforgeeks.org/c-interview-questions/ 32/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
nodes to the result. */
dummy.next = NULL;
while (1) {
if (a == NULL) {
/* if either list runs out, use the
other list */
tail->next = b;
break;
}
else if (b == NULL) {
tail->next = a;
break;
}
if (a->data <= b->data)
MoveNode(&(tail->next), &a);
else
MoveNode(&(tail->next), &b);
tail = tail->next;
}
return (dummy.next);
}
/* UTILITY FUNCTIONS */
/* MoveNode() function takes the node
from the front of the source, and
move it to the front of the dest.
It is an error to call this with the
source list empty.
https://www.geeksforgeeks.org/c-interview-questions/ 33/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
/* link the old list off the new node */
new_node->next = (*head_ref);
push(&b, 20);
push(&b, 3);
push(&b, 2);
return 0;
}
Output
For more information, refer to the article – Merge Two Sorted Linked List
https://www.geeksforgeeks.org/c-interview-questions/ 34/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
getc(): The function reads a single character from an input stream and
returns an integer value (typically the ASCII value of the character) if it
succeeds. On failure, it returns the EOF.
getchar(): Unlike getc(), gechar() can read from standard input; it is
equivalent to getc(stdin).
getch(): It is a nonstandard function and is present in ‘conio.h’ header file
which is mostly used by MS-DOS compilers like Turbo C.
getche(): It reads a single character from the keyboard and displays it
immediately on the output screen without waiting for enter key.
Summer-time is here and so is the time to skill-up! More than 5,000 learners
have now completed their journey from basics of DSA to advanced level
development programs such as Full-Stack, Backend Development, Data
Science.
And why go anywhere else when our DSA to Development: Coding Guide
will help you master all this in a few months! Apply now to our DSA to
Development Program and our counsellors will connect with you for further
guidance & support.
kaml… Follow 53
Next Article
C Programming Interview Questions
(2024)
Similar Reads
We useData
cookiesEngineer
to ensure you have the bestQuestions:
Interview browsing experience
Top on60ourPlus
website. By using and Answers f…
Questions
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 35/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Kafka Interview Questions - Top 70+ Questions and Answers for 2024
Apache Kafka has become a cornerstone in modern distributed systems and
data-driven architectures. As organizations increasingly adopt real-time data…
15+ min read
https://www.geeksforgeeks.org/c-interview-questions/ 36/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
5 min read
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 37/39
7/28/24, 12:50 AM Top 50 C Programming Interview Questions and Answers
Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
Advertise with us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Geeks Community
Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL DSA Interview Questions
R Language Competitive Programming
Android Tutorial
We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
https://www.geeksforgeeks.org/c-interview-questions/ 39/39