C Programming Important Questions & Answers
1) What is function? Explain function declaration, function definition, function
call? [2015]
A function is a self-contained block of code that performs a specific task.
Function Declaration: Tells the compiler about the function’s name, return
type, and parameters.
Example: int add(int, int);
Function Definition: Provides the actual body of the function.
int add(int a, int b){
return a+b;
Function Call: Invokes the function.
Example: sum = add(5,3);
2) List and explain the scope of variable? [2019]
The scope of a variable refers to the region where the variable is accessible.
1. Local Variable – Declared inside a function, accessible only there.
2. Global Variable – Declared outside all functions, accessible throughout the
program.
3. Formal Parameters – Variables declared inside function headers, scope is
within function.
4. Block Scope – Declared inside { }, accessible only within that block.
3) What is recursive function with an example? [2017]
A recursive function is one that calls itself directly or indirectly until a base
condition is satisfied.
Example: Factorial Function
int fact(int n){
if(n==0) return 1;
else return n * fact(n-1);
}
4) Write a program in C using functions to swap two numbers. [2017]
#include <stdio.h>
void swap(int *a, int *b){
int temp = *a;
*a = *b;
*b = temp;
int main(){
int x=10, y=20;
swap(&x, &y);
printf("x=%d y=%d", x, y);
return 0;
5) What is an array? How to declare and initialize the one-dimensional array
with an example? [2016, 2017, 2019]
An array is a collection of elements of the same type stored in contiguous
memory locations.
Declaration: int arr[5];
Initialization: int arr[5] = {1,2,3,4,5};
Example:
#include <stdio.h>
int main(){
int arr[5] = {10,20,30,40,50};
for(int i=0;i<5;i++)
printf("%d ", arr[i]);
return 0;
6) List and explain the operations of array with an example? [2019]
Common array operations:
1. Traversal – Accessing elements.
for(int i=0;i<n;i++) printf("%d ", arr[i]);
2. Insertion – Adding new element.
3. Deletion – Removing element.
4. Searching – Finding element.
5. Sorting – Arranging elements in order.
7) Explain the call by reference and call by value with a suitable example?
[2022]
Call by Value: A copy of the actual parameter is passed. Changes do not
affect the original variable.
void func(int x){ x=10; }
Call by Reference: Address of variable is passed. Changes affect the original
variable.
void func(int *x){ *x=10; }
8) Write a C program using functions to generate the Fibonacci series. [2019]
#include <stdio.h>
void fib(int n){
int a=0, b=1, c;
for(int i=0;i<n;i++){
printf("%d ", a);
c = a + b;
a = b;
b = c;
}
}
int main(){
fib(10);
return 0;