Most Frequently Asked C Programming Language Questions for Freshers
Here are some C programming language-related technical questions frequently asked in interviews. I'm going to answer each question briefly along with the questions.
Technical Questions in C
Question 1: What is C?
C is a widely used, simple, and general-purpose computer language. It is a machine-independent, structured programming language widely used to create various apps, operating systems like Windows, and many more complex applications like the Git repository, the MySQL database, the Python interpreter, etc.
Question 2: What are the Applications of C?
C is widely used in many applications, such as embedded systems, for developing system applications and desktop applications, databases including MySQL, and operating systems, including MS Windows, Apple OS, etc.
Question 3: Why C is a mid-level language?
C is a mid-level language since it combines low-level and high-level programming languages.
Question 4: Name basic datatypes in C.
character, integer, floating-point, and double are basic datatypes in C.
Question 5. What is calloc in C?
The calloc function initializes all bytes to zero and allows memory for an array of
elements.
Question 6. Explain the concept of pointers in C.
Pointers are variables that have the values of memory addresses. They give you immediate access to and control over memory locations. Pointers are frequently used for arrays, function parameter passing, and dynamic memory allocation.
Question 7. What is the const keyword used for in C?
Constants are denoted by the term const, which means that once a variable has been initialized, its value cannot be modified.
Question 8. Explain the difference between ++r and r++.
The increment operators ++r and r++ are identical. The pre-increment operator, ++r, raises the r value before returning the raised value. The post-increment operator, r++, increments r after returning the current r value.
Question 9. What are function pointers in C?
Function pointers are pointers that point to the memory addresses of functions. They allow you to call a function indirectly through the pointer. They're often used in advanced programming scenarios like callback functions and dynamic function invocation.
Question 10. What is the use of the volatile keyword in C?
The volatile keyword indicates that a variable can be changed by sources outside of the program's control. It prevents the compiler from optimizing away reads or writes to the variable, ensuring that every access is treated as a genuine memory operation.
Coding questions in C
Remember that understanding the logic and strategy behind a solution is just as important to coding as achieving the right answer.
Question 1. Write code that calculates the sum of its digits(integers).
Here is the program for finding the sum of digits:
#include <stdio.h>
int main() {
int num, sum = 0, digit;
printf("Enter an integer: ");
scanf("%d", &num);
while (num > 0) {
digit = num % 10;
sum += digit;
num /= 10;
}
printf("Sum of digits: %d\n", sum);
return 0;
}
Output:
![Most Frequently Asked C Programming Language Questions for Freshers](https://static.tutorialandexample.com/c/most-frequently-asked-c-programming-language-questions-for-freshers1.png)
Question 2. Write code to calculate the factorial of a given positive integer.
Program for factorial of any given positive integer:
#include <stdio.h>
int main() {
int num, factorial = 1;
printf("Enter a positive integer: ");
scanf("%d", &num);
for (int i = 1; i <= num; i++) {
factorial *= i;
}
printf("Factorial: %d\n", factorial);
return 0;
}
Output:
![Most Frequently Asked C Programming Language Questions for Freshers](https://static.tutorialandexample.com/c/most-frequently-asked-c-programming-language-questions-for-freshers2.png)
Question 3. Write code to generate the Fibonacci series for various terms.
#include <stdio.h>
int main() {
int num, first = 0, second = 1, next;
printf("Enter the number of terms: ");
scanf("%d", &num);
printf("Fibonacci Series: ");
for (int i = 0; i < num; i++) {
printf("%d, ", first);
next = first + second;
first = second;
second = next;
}
printf("\n");
return 0;
}
Output:
![Most Frequently Asked C Programming Language Questions for Freshers](https://static.tutorialandexample.com/c/most-frequently-asked-c-programming-language-questions-for-freshers3.png)
Question 4. Write a C program to swap the values of two variables.
#include <stdio.h>
int main() {
int a, b;
printf("Enter two integers:\n");
scanf("%d %d", &a, &b);
printf("Before swapping: a = %d, b = %d\n", a, b);
a = a + b;
b = a - b;
a = a - b;
printf("After swapping: a = %d, b = %d\n", a, b);
return 0;
}
Output:
![Most Frequently Asked C Programming Language Questions for Freshers](https://static.tutorialandexample.com/c/most-frequently-asked-c-programming-language-questions-for-freshers4.png)
Question 5. Write code to check if a given positive integer is a prime number.
#include <stdio.h>
int main() {
int num, isPrime = 1;
printf("Enter a positive integer: ");
scanf("%d", &num);
if (num <= 1) {
isPrime = 0;
} else {
for (int value = 2; value * value <= num; value++) {
if (num % value == 0) {
isPrime = 0;
break;
}
}
}
printf("Prime\n");
} else {
printf("Not a prime\n");
}
return 0;
}
Output:
![Most Frequently Asked C Programming Language Questions for Freshers](https://static.tutorialandexample.com/c/most-frequently-asked-c-programming-language-questions-for-freshers5.png)