C Programming Placement Questions
C Programming Questions for Placement 2026 (with Solutions)
Last Updated: March 2026
Introduction
C programming remains a foundational language in computer science education and technical placement exams. Despite the emergence of newer languages, C continues to be tested extensively by companies like TCS, Infosys, Wipro, Cognizant, Accenture, Capgemini, and product-based companies. Its emphasis on pointers, memory management, and low-level operations makes it an excellent test of programming fundamentals.
Why C Programming is Important for Placements
- Foundation of Programming: C concepts apply to most modern languages
- System Programming: Essential for OS, embedded systems, and drivers
- Memory Management: Tests understanding of pointers, stack, and heap
- Problem-Solving: Develops algorithmic thinking and logical reasoning
- Interview Standard: Commonly used in coding interviews and technical tests
Companies Testing C Programming
| Company | Difficulty | Common Topics |
|---|---|---|
| TCS | Easy-Moderate | Basics, arrays, strings, functions |
| Infosys | Moderate | Pointers, structures, file handling |
| Wipro | Easy-Moderate | Control structures, arrays, recursion |
| Cognizant | Moderate | Pointers, memory allocation, strings |
| Accenture | Easy | Fundamentals, loops, conditionals |
| Capgemini | Moderate | Data structures in C, pointers |
| Product Companies | Hard | Advanced pointers, bit manipulation |
Frequently Asked Coding Questions with Solutions
Question 1: Factorial Using Recursion
Problem: Write a C program to calculate factorial of a number using recursion.
Solution:
#include <stdio.h>
long long factorial(int n) {
// Base case
if (n == 0 || n == 1)
return 1;
// Recursive case
else
return n * factorial(n - 1);
}
int main() {
int num;
printf("Enter a positive integer: ");
scanf("%d", &num);
if (num < 0) {
printf("Factorial is not defined for negative numbers.\n");
} else {
printf("Factorial of %d = %lld\n", num, factorial(num));
}
return 0;
}
Output:
Enter a positive integer: 5
Factorial of 5 = 120
Explanation: The function calls itself with decreasing values until reaching the base case (0 or 1), then returns the product of all numbers.
Question 2: Reverse a String
Problem: Write a C program to reverse a string without using library functions.
Solution:
#include <stdio.h>
void reverseString(char str[]) {
int i, j;
char temp;
// Find string length
for (i = 0; str[i] != '\0'; i++);
// Reverse using two-pointer technique
for (j = 0; j < i / 2; j++) {
temp = str[j];
str[j] = str[i - 1 - j];
str[i - 1 - j] = temp;
}
}
int main() {
char str[100];
printf("Enter a string: ");
gets(str); // Note: Use fgets in production code
printf("Original string: %s\n", str);
reverseString(str);
printf("Reversed string: %s\n", str);
return 0;
}
Output:
Enter a string: Hello World
Original string: Hello World
Reversed string: dlroW olleH
Question 3: Check Prime Number
Problem: Write a C program to check if a number is prime.
Solution:
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
bool isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
// Check only up to square root
for (int i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (isPrime(num))
printf("%d is a prime number.\n", num);
else
printf("%d is not a prime number.\n", num);
return 0;
}
Output:
Enter a number: 17
17 is a prime number.
Question 4: Bubble Sort
Problem: Implement bubble sort to sort an array in ascending order.
Solution:
#include <stdio.h>
void bubbleSort(int arr[], int n) {
int i, j, temp;
int swapped;
for (i = 0; i < n - 1; i++) {
swapped = 0;
for (j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
// Swap elements
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
swapped = 1;
}
}
// If no swapping occurred, array is sorted
if (swapped == 0)
break;
}
}
void printArray(int arr[], int size) {
for (int i = 0; i < size; i++)
printf("%d ", arr[i]);
printf("\n");
}
int main() {
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(arr) / sizeof(arr[0]);
printf("Original array: ");
printArray(arr, n);
bubbleSort(arr, n);
printf("Sorted array: ");
printArray(arr, n);
return 0;
}
Output:
Original array: 64 34 25 12 22 11 90
Sorted array: 11 12 22 25 34 64 90
Question 5: Linked List Implementation
Problem: Implement a singly linked list with insert, delete, and display operations.
Solution:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
// Insert at beginning
void insertAtBeginning(struct Node** head, int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = *head;
*head = newNode;
}
// Delete a node
void deleteNode(struct Node** head, int key) {
struct Node *temp = *head, *prev;
if (temp != NULL && temp->data == key) {
*head = temp->next;
free(temp);
return;
}
while (temp != NULL && temp->data != key) {
prev = temp;
temp = temp->next;
}
if (temp == NULL) return;
prev->next = temp->next;
free(temp);
}
// Display list
void displayList(struct Node* node) {
while (node != NULL) {
printf("%d -> ", node->data);
node = node->next;
}
printf("NULL\n");
}
int main() {
struct Node* head = NULL;
insertAtBeginning(&head, 3);
insertAtBeginning(&head, 7);
insertAtBeginning(&head, 1);
insertAtBeginning(&head, 9);
printf("Linked List: ");
displayList(head);
deleteNode(&head, 7);
printf("After deleting 7: ");
displayList(head);
return 0;
}
Output:
Linked List: 9 -> 1 -> 7 -> 3 -> NULL
After deleting 7: 9 -> 1 -> 3 -> NULL
Question 6: Binary Search
Problem: Implement binary search on a sorted array.
Solution:
#include <stdio.h>
int binarySearch(int arr[], int left, int right, int key) {
while (left <= right) {
int mid = left + (right - left) / 2;
if (arr[mid] == key)
return mid;
if (arr[mid] < key)
left = mid + 1;
else
right = mid - 1;
}
return -1; // Element not found
}
int main() {
int arr[] = {2, 3, 4, 10, 40, 50, 70};
int n = sizeof(arr) / sizeof(arr[0]);
int key = 10;
int result = binarySearch(arr, 0, n - 1, key);
if (result == -1)
printf("Element not found\n");
else
printf("Element found at index %d\n", result);
return 0;
}
Output:
Element found at index 3
Question 7: Stack Implementation using Arrays
Problem: Implement a stack using arrays with push, pop, and peek operations.
Solution:
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
struct Stack {
int arr[MAX];
int top;
};
void initStack(struct Stack* s) {
s->top = -1;
}
int isFull(struct Stack* s) {
return s->top == MAX - 1;
}
int isEmpty(struct Stack* s) {
return s->top == -1;
}
void push(struct Stack* s, int value) {
if (isFull(s)) {
printf("Stack Overflow\n");
return;
}
s->arr[++(s->top)] = value;
printf("Pushed %d\n", value);
}
int pop(struct Stack* s) {
if (isEmpty(s)) {
printf("Stack Underflow\n");
return -1;
}
return s->arr[(s->top)--];
}
int peek(struct Stack* s) {
if (isEmpty(s)) {
printf("Stack is empty\n");
return -1;
}
return s->arr[s->top];
}
int main() {
struct Stack s;
initStack(&s);
push(&s, 10);
push(&s, 20);
push(&s, 30);
printf("Top element: %d\n", peek(&s));
printf("Popped: %d\n", pop(&s));
printf("Top element after pop: %d\n", peek(&s));
return 0;
}
Output:
Pushed 10
Pushed 20
Pushed 30
Top element: 30
Popped: 30
Top element after pop: 20
Question 8: Palindrome Check
Problem: Check if a string is palindrome (reads same forwards and backwards).
Solution:
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
bool isPalindrome(char str[]) {
int left = 0;
int right = strlen(str) - 1;
while (left < right) {
// Skip non-alphanumeric characters
while (left < right && !isalnum(str[left]))
left++;
while (left < right && !isalnum(str[right]))
right--;
// Compare characters (case insensitive)
if (tolower(str[left]) != tolower(str[right]))
return false;
left++;
right--;
}
return true;
}
int main() {
char str[] = "A man a plan a canal Panama";
if (isPalindrome(str))
printf("'%s' is a palindrome\n", str);
else
printf("'%s' is not a palindrome\n", str);
return 0;
}
Output:
'A man a plan a canal Panama' is a palindrome
Question 9: File Handling - Read and Write
Problem: Write a program to read from one file and write to another.
Solution:
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *source, *target;
char ch;
// Open source file
source = fopen("source.txt", "r");
if (source == NULL) {
printf("Cannot open source file\n");
exit(1);
}
// Open target file
target = fopen("target.txt", "w");
if (target == NULL) {
printf("Cannot open target file\n");
fclose(source);
exit(1);
}
// Copy content
while ((ch = fgetc(source)) != EOF) {
fputc(ch, target);
}
printf("File copied successfully\n");
fclose(source);
fclose(target);
return 0;
}
Question 10: Matrix Multiplication
Problem: Multiply two matrices and display the result.
Solution:
#include <stdio.h>
#define MAX 10
void multiplyMatrices(int first[MAX][MAX], int second[MAX][MAX],
int result[MAX][MAX], int r1, int c1, int r2, int c2) {
// Initialize result matrix
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c2; j++) {
result[i][j] = 0;
}
}
// Multiply matrices
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c2; j++) {
for (int k = 0; k < c1; k++) {
result[i][j] += first[i][k] * second[k][j];
}
}
}
}
void displayMatrix(int matrix[MAX][MAX], int row, int col) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}
int main() {
int first[MAX][MAX] = {{1, 2}, {3, 4}};
int second[MAX][MAX] = {{5, 6}, {7, 8}};
int result[MAX][MAX];
printf("First Matrix:\n");
displayMatrix(first, 2, 2);
printf("\nSecond Matrix:\n");
displayMatrix(second, 2, 2);
multiplyMatrices(first, second, result, 2, 2, 2, 2);
printf("\nResult Matrix:\n");
displayMatrix(result, 2, 2);
return 0;
}
Output:
First Matrix:
1 2
3 4
Second Matrix:
5 6
7 8
Result Matrix:
19 22
43 50
Output Prediction Questions (10 Questions)
Question 1: What is the output?
#include <stdio.h>
int main() {
int a = 5, b = 10;
printf("%d", a++ + ++b);
return 0;
}
Question 2: What is the output?
#include <stdio.h>
int main() {
int x = 10;
printf("%d %d %d", x, x++, ++x);
return 0;
}
Question 3: What is the output?
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
printf("%d", *(arr + 2));
return 0;
}
Question 4: What is the output?
#include <stdio.h>
void fun(int *p) {
*p = *p + 10;
}
int main() {
int x = 5;
fun(&x);
printf("%d", x);
return 0;
}
Question 5: What is the output?
#include <stdio.h>
#define SQUARE(x) x*x
int main() {
printf("%d", SQUARE(3+2));
return 0;
}
Question 6: What is the output?
#include <stdio.h>
int main() {
char str[] = "Hello";
printf("%lu %lu", sizeof(str), strlen(str));
return 0;
}
Question 7: What is the output?
#include <stdio.h>
int main() {
int a = 1, b = 2, c = 3;
printf("%d", a += b += c);
return 0;
}
Question 8: What is the output?
#include <stdio.h>
int main() {
int i = 0;
for(;;) {
if(i == 5) break;
printf("%d ", i++);
}
return 0;
}
Question 9: What is the output?
#include <stdio.h>
struct Test {
int x;
char y;
};
int main() {
struct Test t = {10, 'A'};
printf("%lu", sizeof(t));
return 0;
}
Question 10: What is the output?
#include <stdio.h>
int main() {
int a = 5;
int b = a & 3;
printf("%d", b);
return 0;
}
MCQs on C Fundamentals (10 Questions)
Question 1: What is the size of int in C? (Assume 32-bit system)
a) 2 bytes b) 4 bytes c) 8 bytes d) Depends on compiler
Question 2: What does the sizeof operator return?
a) The value of a variable b) The size of a variable in bytes c) The address of a variable d) The type of a variable
Question 3: What is the default return type of a function in C?
a) void b) int c) float d) double
Question 4: Which of the following is not a storage class?
a) auto b) register c) define d) static
Question 5: What is the purpose of extern keyword?
a) To declare a variable defined in another file b) To allocate memory c) To define a constant d) To create a static variable
Question 6: Which operator has the highest precedence?
a) + (addition) b) * (multiplication) c) () (parentheses) d) = (assignment)
Question 7: What is a dangling pointer?
a) A pointer pointing to NULL b) A pointer pointing to a deallocated memory location c) A pointer that is not initialized d) A void pointer
Question 8: What is the output of printf("%d", 8 % 3)?
a) 2 b) 2.66 c) 0 d) 3
Question 9: What does strcat() function do?
a) Compares two strings b) Concatenates two strings c) Copies one string to another d) Calculates string length
Question 10: What is the difference between malloc() and calloc()?
a) No difference
b) malloc initializes memory to zero, calloc does not
c) calloc initializes memory to zero, malloc does not
d) malloc is faster than calloc
Tips for C Programming Coding Rounds
1. Master Pointers
- Understand pointer arithmetic
- Practice with arrays and strings using pointers
- Know the difference between
*p,**p, and&p
2. Memory Management
- Always free dynamically allocated memory
- Understand stack vs heap allocation
- Watch for memory leaks and dangling pointers
3. String Handling
- Remember strings are null-terminated
- Know standard library functions
- Practice without using library functions
4. Recursion
- Always define base case first
- Understand call stack behavior
- Practice classic problems (factorial, fibonacci, tower of hanoi)
5. Data Structures
- Be comfortable with arrays, linked lists, stacks, queues
- Practice tree traversals
- Understand hash tables basics
6. Debugging Skills
- Use print statements effectively
- Understand common errors (segmentation fault, bus error)
- Practice tracing code manually
Frequently Asked Questions (FAQ)
Q1: Is C still relevant for placements in 2026?
Yes, C remains highly relevant. It tests fundamental programming concepts, memory management, and pointer operations that are essential for system-level programming and form the foundation for C++, Java, and other languages.
Q2: What are the most important C topics for placements?
Focus on: Pointers and pointer arithmetic, Arrays and strings, Structures and unions, Dynamic memory allocation (malloc, calloc, free), File handling, Recursion, Linked lists, and Basic sorting/searching algorithms.
Q3: Should I use recursion or iteration?
Use iteration for efficiency (no stack overhead). Use recursion when it significantly simplifies code (tree traversals, divide-and-conquer algorithms). In interviews, know both approaches.
Q4: How do I handle segmentation faults?
Common causes: accessing NULL pointer, array out of bounds, using freed memory, stack overflow. Use debugging tools like GDB or add print statements to trace execution.
Q5: What's the difference between ++i and i++?
++i (pre-increment): increment first, then use the value.
i++ (post-increment): use the value first, then increment.
In standalone statements, both are equivalent. In expressions, the difference matters.
Master C programming through consistent practice. Focus on understanding memory management, pointers, and data structures. Practice writing clean, efficient code and always trace your programs manually. Good luck with your placement preparation!
Explore this topic cluster
More resources in Uncategorized
Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.