C Language Practice Questions & Assignments
This page contains Multiple Choice Questions (MCQs), short answer questions, programming-based assignment questions, and lab practice exercises commonly asked in university examinations, lab exams, and programming interviews. Practice these questions to strengthen your C programming fundamentals and problem-solving skills.
Multiple Choice Questions (MCQs)
These MCQs help you revise basic C syntax, operators, data types, arrays, strings, functions, pointers, and fundamental concepts.
1. What is the output of the following code?
printf("%d", sizeof(int));- A.1
- B.2
- C.4
- D.Depends on compiler
2. Which operator has the highest precedence?
- A.+
- B.*
- C.()
- D.=
3. What is the default return type of a function in C?
- A.void
- B.int
- C.char
- D.float
4. Which of the following is a valid way to declare a pointer?
- A.int ptr;
- B.*int ptr;
- C.int *ptr;
- D.int ptr*;
5. What is the size of a char array needed to store "Hello"?
- A.5
- B.6
- C.7
- D.8
6. Which header file is required for printf() and scanf()?
- A.<string.h>
- B.<stdlib.h>
- C.<stdio.h>
- D.<math.h>
7. What is the value of 5 % 2?
- A.2
- B.1
- C.0
- D.2.5
8. Which loop executes at least once?
- A.for
- B.while
- C.do-while
- D.None of the above
9. What does & operator return?
- A.Value of variable
- B.Address of variable
- C.Size of variable
- D.Type of variable
10. Which function is used to find string length?
- A.strlen()
- B.strcpy()
- C.strcat()
- D.strcmp()
11. Array index in C starts from:
- A.0
- B.1
- C.-1
- D.Depends on declaration
12. What is arr[0] if arr is declared as int arr[5]?
- A.Last element
- B.First element
- C.Invalid
- D.Second element
13. Which function copies one string to another?
- A.strlen()
- B.strcpy()
- C.strcat()
- D.strcmp()
14. String in C is terminated by:
- A.' ' (space)
- B.'\n' (newline)
- C.'\0' (null)
- D.'\t' (tab)
15. What is the maximum size of an array in C?
- A.100
- B.1000
- C.Fixed at compile time
- D.Depends on memory
Short Answer Questions
Answer these questions in 2-3 lines. These questions test your understanding of C programming concepts and terminology.
1. What is C programming language?
2. Explain the difference between = and == operators.
3. What is a variable? Give examples.
4. Explain printf() and scanf() functions.
5. What are format specifiers? Give examples.
6. Differentiate between if and switch statement.
7. Explain break and continue statements.
8. What is an array? How is it declared?
9. Explain string in C.
10. What is a function? List its advantages.
11. Explain call by value and call by reference.
12. What is a pointer? Why is it used?
13. Explain NULL pointer and void pointer.
14. What is structure? Give example.
15. Differentiate between structure and union.
16. Explain dynamic memory allocation.
17. What is file handling? List file operations.
18. Explain command line arguments.
19. What are preprocessor directives?
20. Explain scope and lifetime of variables.
Output-Based Questions
Predict the output of the following C programs before revealing the answer. These questions test your understanding of code execution flow.
1. What is the output of the following program?
#include <stdio.h>
int main() {
int x = 5;
int y = ++x + x++;
printf("%d %d", x, y);
return 0;
}2. What is the output of the following program?
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
printf("%d", arr[5]);
return 0;
}3. What is the output of the following program?
#include <stdio.h>
int main() {
int a = 10;
int *ptr = &a;
printf("%d %d", *ptr, a);
return 0;
}4. What is the output of the following program?
#include <stdio.h>
int main() {
int i;
for (i = 0; i < 5; i++);
printf("%d", i);
return 0;
}5. What is the output of the following program?
#include <stdio.h>
int main() {
int x = 10, y = 20;
if (x = 20) {
printf("True");
} else {
printf("False");
}
return 0;
}Programming / Long Answer Questions
Write complete C programs for these questions. Practice writing code for each question and test it thoroughly.
1. Write a program to find factorial of a number using recursion and iteration.
2. Write a program to check if a number is prime or not. Optimize it.
3. Write a program to find GCD and LCM of two numbers.
4. Write a program to print Fibonacci series up to n terms.
5. Write a program to check if a string is palindrome or not.
6. Write a program to sort an array using bubble sort algorithm.
7. Write a program to perform matrix addition and multiplication.
8. Write a program to implement linear search and binary search.
9. Write a program to count vowels, consonants, digits in a string.
10. Write a program to reverse a string without using library function.
11. Write a program to swap two numbers using pointers.
12. Write a program to demonstrate use of structures (Student database).
13. Write a program to dynamically allocate memory for array and perform operations.
14. Write a program to read from file and write to another file.
15. Write a program to count words, lines, characters in a text file.
16. Write a program to implement stack using array.
17. Write a program to find second largest element in array.
18. Write a program to remove duplicates from array.
19. Write a program to merge two sorted arrays.
20. Write a program using command line arguments to perform calculator operations.
Lab Practice Questions
Organized by lab sessions, these questions cover basic programs to advanced concepts progressively.
Lab 1: Basic Programs
- Program to display "Hello World"
- Program to add two numbers
- Program to find area of circle
- Program to swap two numbers
- Program to calculate simple interest
Lab 2: Control Statements
- Program to find largest of three numbers
- Program to check even or odd
- Program to check leap year
- Program to print day name using switch
- Program to check alphabet, digit or special character
Lab 3: Loops
- Program to print multiplication table
- Program to find sum of digits
- Program to reverse a number
- Program to check Armstrong number
- Program to print patterns (star, number patterns)
Lab 4: Arrays
- Program to find largest and smallest in array
- Program to reverse an array
- Program to merge two arrays
- Program to find frequency of elements
- Program for matrix transpose
Lab 5: Functions
- Program with functions for mathematical operations
- Program to check prime using function
- Program to find factorial using recursion
- Program with function overloading concepts
- Program using static variables
Lab 6: Pointers and Strings
- Program to swap using pointers
- Program to access array using pointers
- Program for string operations (copy, compare, concatenate)
- Program to count words in string
- Program to remove spaces from string
Lab 7: Structures
- Program for student record management
- Program for employee database
- Program using nested structures
- Program with array of structures
- Program using structure pointers
Lab 8: File Handling
- Program to create and write to file
- Program to read from file
- Program to copy file contents
- Program to append data to file
- Program for student data file operations
Assignment Questions for Students
Weekly assignments organized by topics to help you practice systematically throughout the semester.
Assignment 1: Basic Concepts (Week 1-2)
- Write programs demonstrating all operators in C
- Create a simple calculator program
- Write programs for all control structures
- Document all programs with comments
Assignment 2: Arrays and Strings (Week 3-4)
- Implement sorting algorithms (bubble, selection, insertion)
- Implement searching algorithms (linear, binary)
- Create string manipulation programs
- Programs on 2D arrays and matrices
Assignment 3: Functions and Pointers (Week 5-6)
- Create a library of utility functions
- Programs demonstrating pointer arithmetic
- Programs on call by value vs call by reference
- Recursive problem solving
Assignment 4: Advanced Concepts (Week 7-8)
- Student management system using structures
- File handling application
- Dynamic memory allocation programs
- Mini project combining all concepts
📝 Study Tip
Practice these questions regularly. Start with MCQs and short answers, then move to programming questions. Write code for each programming question and test it thoroughly. Understanding concepts is more important than memorizing.