Whether you’re preparing for exams, placements, or just sharpening your skills, these C programming Coding questions cover everything from basic syntax to pointers and file handling. Each question includes a clean code example, expected output, and a plain-English explanation of how it works.
Table of Contents
| Section | Topics |
|---|---|
| Basic C Programming Questions | Q1 — Print Hello World |
| Q2 — Sum of Two Numbers | |
| Q3 — Check Odd or Even | |
| Q4 — Factorial Using a Loop | |
| Q5 — Fibonacci Series | |
| Intermediate C Programming Questions | Q6 — Reverse an Array |
| Q7 — Check Palindrome String | |
| Q8 — Factorial Using Recursion | |
| Q9 — Find Largest in Array | |
| Advanced C Programming Questions | Q10 — Swap Using Pointers |
| Q11 — Structure for Student Record | |
| Q12 — Dynamic Memory with malloc | |
| Frequently Asked Questions | FAQs on C Programming |
| Keep Practising | Practice More C Programming Problems |
All code examples compile and run on GCC. Test them on any standard C compiler — onlinegdb.com works great if you don’t have a local setup.
Basic C programming Coding questions
These C programming Coding questions cover fundamental concepts every beginner must know — data types, operators, loops, and conditionals.
- Print Hello WorldEasy
Write a C program to print “Hello, World!” on the screen.
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
Output
Hello, World!
Every C program starts execution from main(). The printf() function prints text to the console. \n moves the cursor to a new line.
2. Sum of two numbersEasy
Write a program to read two integers and print their sum.
#include <stdio.h>
int main() {
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum = %d\n", sum);
return 0;
}
Output
Enter two numbers: 5 3
Sum = 8
scanf() reads input from the user. The & operator passes the memory address of each variable so scanf can store the value directly.
3. Check odd or evenEasy
Write a program to check whether a number is odd or even.
#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
if (n % 2 == 0)
printf("%d is Even\n", n);
else
printf("%d is Odd\n", n);
return 0;
}
Output
Enter a number: 7
7 is Odd
The modulus operator % returns the remainder of division. If a number divides evenly by 2 (remainder 0), it is even. Otherwise it is odd.
4. Factorial using a loopEasy
Write a program to find the factorial of a number using a for loop.
#include <stdio.h>
int main() {
int n, i;
long long fact = 1;
printf("Enter a number: ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
fact *= i;
printf("Factorial of %d = %lld\n", n, fact);
return 0;
}
Output
Enter a number: 5
Factorial of 5 = 120
The loop multiplies every integer from 1 to n. Using long long prevents overflow for larger inputs since factorials grow very fast.
5. Fibonacci seriesEasy
Print the first n terms of the Fibonacci series.
#include <stdio.h>
int main() {
int n, a = 0, b = 1, next, i;
printf("Enter number of terms: ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
printf("%d ", a);
next = a + b;
a = b;
b = next;
}
return 0;
}
Output
Enter number of terms: 7
0 1 1 2 3 5 8
Each term equals the sum of the previous two. The loop updates a and b in each iteration by shifting them forward by one position.

Intermediate C programming questions
These questions test your understanding of arrays, functions, strings, and recursion — the core of any serious C programming practice session.
6. Reverse an array Medium
Write a program to reverse an array of integers.
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int n = 5, i, temp;
for (i = 0; i < n / 2; i++) {
temp = arr[i];
arr[i] = arr[n - 1 - i];
arr[n - 1 - i] = temp;
}
printf("Reversed array: ");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
return 0;
}
Output
Reversed array: 5 4 3 2 1
The loop swaps elements from both ends moving toward the centre. You only need to iterate halfway — swapping past the midpoint would undo previous swaps.
7. Check palindrome stringMedium
Write a program to check whether a string is a palindrome.
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int i, n, flag = 1;
printf("Enter a string: ");
scanf("%s", str);
n = strlen(str);
for (i = 0; i < n / 2; i++) {
if (str[i] != str[n - 1 - i]) {
flag = 0;
break;
}
}
if (flag)
printf("%s is a palindrome\n", str);
else
printf("%s is not a palindrome\n", str);
return 0;
}
Output
Enter a string: madam
madam is a palindrome
The program compares characters from both ends moving inward. If any pair mismatches, the string is not a palindrome. The flag variable tracks whether a mismatch occurred.
8. Factorial using recursionMedium
Write a recursive function to calculate the factorial of a number.
#include <stdio.h>
long long factorial(int n) {
if (n == 0 || n == 1)
return 1;
return n * factorial(n - 1);
}
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
printf("Factorial = %lld\n", factorial(n));
return 0;
}
Output
Enter a number: 6
Factorial = 720
The function calls itself with a smaller value each time until it hits the base case (0 or 1). Each call returns its result to the previous call, building the final answer on the way back up the call stack.
9. Find largest in arrayMedium
Write a program to find the largest element in an array.
#include <stdio.h>
int main() {
int arr[] = {12, 45, 7, 89, 23};
int n = 5, i, max = arr[0];
for (i = 1; i < n; i++) {
if (arr[i] > max)
max = arr[i];
}
printf("Largest element = %d\n", max);
return 0;
}
Output
Largest element = 89
Start by assuming the first element is the largest. The loop checks each remaining element — if any beats the current max, it becomes the new max.
Advanced C programming questions
These C programming questions cover pointers, structures, and memory management — topics that appear frequently in technical interviews and university exams.
10. Swap using pointersAdvanced
Write a function to swap two numbers using pointers.
#include <stdio.h>
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int x = 10, y = 20;
printf("Before swap: x = %d, y = %d\n", x, y);
swap(&x, &y);
printf("After swap: x = %d, y = %d\n", x, y);
return 0;
}
Output
Before swap: x = 10, y = 20
After swap: x = 20, y = 10
Passing variables by value would not change the originals. Passing their addresses lets the function directly modify the values at those memory locations using the dereference operator .
11. Structure for student recordAdvanced
Write a program to store and display student details using a structure.
#include <stdio.h>
struct Student {
char name[50];
int age;
float marks;
};
int main() {
struct Student s1 = {"Arjun", 20, 92.5};
printf("Name : %s\n", s1.name);
printf("Age : %d\n", s1.age);
printf("Marks : %.1f\n", s1.marks);
return 0;
}
Output
Name : Arjun
Age : 20
Marks : 92.5
A struct groups different data types under one name. A single Student variable holds a string, an integer, and a float — accessed using the dot operator.
12. Dynamic memory with mallocAdvanced
Write a program to allocate memory dynamically for an array using malloc.
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, i;
printf("Enter number of elements: ");
scanf("%d", &n);
int *arr = (int*)malloc(n * sizeof(int));
if (arr == NULL) {
printf("Memory allocation failed\n");
return 1;
}
for (i = 0; i < n; i++) {
arr[i] = (i + 1) * 10;
printf("%d ", arr[i]);
}
free(arr);
return 0;
}
Output
Enter number of elements: 4
10 20 30 40
malloc() allocates a block of memory at runtime. Always check if the returned pointer is NULL and always call free() when done to prevent memory leaks.
Frequently asked questions
Which C programming questions appear most in placement interviews?
Interviewers most commonly ask about pointers, string manipulation, recursion, sorting algorithms, and linked lists. Focus on understanding how memory works in C — that separates average answers from strong ones.
How do beginners start practising C programming questions?
Start with basic input/output, then move to loops and conditions, then arrays and strings, and finally pointers and structures. Write every program yourself — don’t just read the solution.
What compiler should beginners use for C programming?
GCC is the standard choice. Install it via Code::Blocks or Dev-C++ on Windows, or use the terminal on Linux/Mac. For quick practice online, onlinegdb.com runs C code instantly in your browser.
What is the difference between arrays and pointers in C?
An array stores a fixed-size collection of elements in contiguous memory. A pointer stores a memory address. Arrays and pointers relate closely — the array name itself acts as a pointer to the first element — but they are not the same thing.
Keep practising
The best way to get better at C programming coding questions is simple: write code every day. Don’t memorise solutions — understand the logic, then close the page and write it yourself from scratch. That is what builds real skill for exams and interviews alike.
Bookmark this page and work through 2–3 questions daily. Start from Question 1 if you’re a beginner — the difficulty builds gradually from basic to advanced.