0% found this document useful (0 votes)
10 views3 pages

C Programming Practice Set

Uploaded by

bitopankalita868
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

C Programming Practice Set

Uploaded by

bitopankalita868
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C Programming Practice Set

Part 1: Coding Exercises

1. Write a function in C to calculate the factorial of a number using recursion.

2. Write a program to reverse a string without using any library function.

3. Write a function that takes an integer array and its size as input and returns the largest element in the

array.

4. Write a program that uses pointers to swap two integers.

5. Write a function that counts the number of vowels in a given string.

Part 2: Debug-the-Code Challenges

1. Pointer Initialization

int main() {

int a = 10;

int *ptr;

*ptr = a;

printf("%d", *ptr);

return 0;

Problem: Program crashes. Why?

2. Array Index Error

int main() {

int arr[5] = {1, 2, 3, 4, 5};

printf("%d", arr[5]);

return 0;
C Programming Practice Set

Problem: Output is undefined or gives garbage value.

3. String Termination Error

int main() {

char str[5] = {'H', 'e', 'l', 'l', 'o'};

printf("%s", str);

return 0;

Problem: String does not print correctly.

4. Memory Allocation

int main() {

int *arr;

arr = malloc(10); // allocate memory

for (int i = 0; i < 10; i++) {

arr[i] = i;

printf("%d", arr[9]);

return 0;

Problem: Sometimes crashes or gives incorrect output.

5. Loop Logic Error

int main() {
C Programming Practice Set

int i = 0;

while (i = 10) {

printf("Loop\n");

i++;

return 0;

Problem: Infinite loop. Why?

You might also like