0% found this document useful (0 votes)
2 views6 pages

C Program

The document contains important questions and answers related to C programming, covering topics such as functions, variable scope, recursive functions, arrays, and parameter passing methods. Key concepts include function declaration, definition, and calls, as well as examples of swapping numbers, generating Fibonacci series, and array operations. It also explains call by value and call by reference with suitable examples.

Uploaded by

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

C Program

The document contains important questions and answers related to C programming, covering topics such as functions, variable scope, recursive functions, arrays, and parameter passing methods. Key concepts include function declaration, definition, and calls, as well as examples of swapping numbers, generating Fibonacci series, and array operations. It also explains call by value and call by reference with suitable examples.

Uploaded by

kumarsanjana45
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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;

You might also like