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

C Programming Basics: MCQs and Concepts

The document contains multiple-choice questions (MCQs), short questions, and long questions related to programming concepts, specifically focusing on C programming language. It covers topics such as Integrated Development Environments (IDEs), syntax, data types, operators, and control statements. Each section aims to assess understanding and knowledge of programming fundamentals and C language specifics.

Uploaded by

adnanwitcher1
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 views34 pages

C Programming Basics: MCQs and Concepts

The document contains multiple-choice questions (MCQs), short questions, and long questions related to programming concepts, specifically focusing on C programming language. It covers topics such as Integrated Development Environments (IDEs), syntax, data types, operators, and control statements. Each section aims to assess understanding and knowledge of programming fundamentals and C language specifics.

Uploaded by

adnanwitcher1
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

Chapter 1

MCQs (25):

1. What is a collection of all the necessary tools for programming called? 1

a) A programming language

b) A programming environment

c) A compiler

d) A text editor

2. Which of the following is an example of an IDE for C programming language?


2

a) Python

b) Xcode

c) Java

d) PHP

3. What is the primary function of an Integrated Development Environment


(IDE)? 3

a) To convert a high-level language program to machine code

b) To write and edit computer programs

c) To provide a programming environment for writing and executing programs

d) To help a programmer debug a program

4. A text editor is a software that allows programmers to perform which of the


following tasks? 4

a) Execute programs

b) Compile programs

c) Debug programs

d) Write and edit programs

5. What is a compiler responsible for? 5

a) Converting a program to machine language code

b) Editing a program
c) Providing a graphical user interface

d) Helping in debugging a program

6. What is the set of rules for writing an accurate program in a programming


language known as? 6

a) Grammar

b) Compiler

c) Syntax

d) Reserved words

7. When a programmer does not follow the proper syntax of a programming


language, what kind of error is generated? 7

a) Logical error

b) Run-time error

c) Syntax error

d) Linker error

8. Words that are predefined and have a specific meaning already known to the
compiler are called: 888

a) User-defined words

b) Keywords

c) Variables

d) Constants

9. The three main parts of a C program are: 999

a) Link section, main section, compiler

b) Header section, main section, body of main()

c) Compiler, text editor, debugger

d) Constants, variables, comments

10. The main() function is the starting point of what in a C program? 101010

a) Compilation

b) Debugging

c) Execution
d) Linking

11. Statements in a program that are ignored by the compiler and are used to
provide a description of the code are called: 111111

a) Variables

b) Keywords

c) Constants

d) Comments

12. Which of the following is an example of a single-line comment in C? 12

a) /* This is a comment */

b) // This is a comment

c) # This is a comment

d) ``

13. What is the purpose of multi-line comments? 131313

a) To execute multiple statements at once

b) To describe code over multiple lines

c) To declare multiple variables

d) To include multiple header files

14. What are values that cannot be changed by a program called? 141414

a) Variables

b) Keywords

c) Constants

d) Identifiers

15. Which of the following is an example of an integer constant? 15

a) 3.14

b) 'a'

c) -2349

d) "Hello"

16. What is a variable? 161616


a) A value that cannot be changed

b) A predefined keyword

c) A name given to a memory location

d) A type of constant

17. Which of the following data types is used to store real numbers (numbers
with a floating point)? 17

a) int

b) char

c) float

d) double

18. The int data type is used to store what kind of numbers? 18

a) Whole numbers

b) Numbers with a decimal point

c) Single characters

d) Strings

19. How many bytes of memory does a char variable take up for storage? 19

a) 2 bytes

b) 4 bytes

c) 1 byte

d) 8 bytes

20. What is the rule for specifying a variable name? 20

a) It must begin with a digit.

b) It can contain spaces.

c) A reserved word can be used.

d) It must begin with a letter or an underscore.

21. What is the process of assigning a value to a variable for the first time
called? 21

a) Variable declaration

b) Variable initialization
c) Variable assignment

d) Variable definition

22. What does variable declaration include? 22

a) Assigning a value to the variable.

b) Specifying its data type and giving it a valid name.

c) Storing the variable in memory.

d) Changing the value of the variable.

23. In the C language, what symbol is used to terminate each statement? 23

a) . (period)

b) ; (semicolon)

c) : (colon)

d) } (curly brace)

24. A C program must contain a main() function because: 242424

a) It contains the header files.

b) It is where the program ends.

c) It is the starting point of execution.

d) It includes all the comments.

25. The header section of a C program includes files that contain what? 25

a) The main function

b) The body of the program

c) Definitions for functions used in the program

d) Comments

Short Questions (30):

1. What is a computer program or software? 26

2. What is a programmer? 27

3. What is a programming language? 28

4. What is a programming environment and why is it essential? 29


5. What does IDE stand for, and what is its purpose? 30

6. Name any three IDEs for C programming language. 31

7. What is a text editor in the context of programming? 32

8. How do computers understand and work with a program written in a high-level


language? 33

9. What is the role of a compiler? 34

10. Define

syntax in programming. 35

11. What is a syntax error? 36

12. What are reserved words or keywords? 37

13. Give five examples of reserved words in C language. 38

14. What are the three main parts of the structure of a C program? 393939

15. What is the purpose of the link section or header section? 40

16. What is the main section of a C program? 41

17. What is the purpose of comments in a program? 42

18. What are the two types of comments in C programming language? 43

19. What is a constant? 444444

20. Name the three types of constants in C. 45

21. What is the difference between an integer constant and a real constant? 46

22. Define a character constant. 47

23. What is a variable, and what does it represent? 48

24. What are the three data types discussed in Chapter 1? 49

25. What is the difference between a signed

int and an unsigned int? 50

26. What is the purpose of specifying a data type for a variable? 51

27. State the rules for specifying a variable name. 52

28. What is variable declaration? 53

29. What is variable initialization? 54


30. Explain the difference between

variable declaration and variable initialization. 55

Long Questions (6):

1. What is an Integrated Development Environment (IDE)? Explain its components


and advantages for a programmer. 56

2. What is the role of a compiler in C programming? Explain the process of program


execution from a high-level language program file to an executable program. 57

3. Explain the structure of a C program in detail, describing the purpose of each of


its main parts. 58

4. Discuss the purpose and syntax of comments in C programs. Provide examples


for both types of comments. 595959

5. What are constants and variables? Differentiate between them and explain the
different types of constants with examples. 606060

6. Define variables and explain the process of declaring and initializing a variable
with the help of examples. 61

Chapter 2

MCQs (25):

1. Which function is a built-in function in C programming language to show


output on the screen? 62

a) scanf()

b) printf()

c) getch()

d) main()

2. The printf() function displays what is written inside the: 63

a) single quotes

b) curly braces

c) double quotes
d) parentheses

3. What are used to specify the format of data that we want to display using
printf()? 64

a) Format specifiers

b) Operators

c) Escape sequences

d) Statement terminators

4. Which format specifier is used to display int data type? 65

a) %f

b) %c

c) %d or %i

d) %s

5. Which format specifier is used for the float data type? 66

a) %f

b) %d

c) %c

d) %s

6. The scanf() function is a built-in function in C language that takes what from
the user? 67

a) Output

b) Input

c) A program

d) A variable

7. The %c format specifier is used to specify which data type for input? 68

a) Integer

b) Float

c) Character

d) String

8. What is used at the end of a statement to indicate its completion? 69


a) Comma (,)

b) Semicolon (;)

c) Colon (:)

d) Period (.)

9. Which of the following is an example of an escape sequence? 70

a) %d

b) \n

c) main()

d) printf()

10. Escape sequences are used to represent: 71

a) Mathematical operations

b) Special characters

c) Variables

d) Data types

11. Which operator is used to assign a value to a variable? 72

a) ==

b) !

c) =

d) +

12. Which of the following is an arithmetic operator? 73

a) <

b) &&

c) %

d) ==

13. What does the + operator do? 74

a) Subtraction

b) Addition

c) Division
d) Multiplication

14. Which operator is used for modulus (remainder)? 75

a) /

b) *

c) %

d) -

15. Which of the following is a relational operator? 76

a) +

b) =

c) >

d) &&

16. The == operator is used to check for: 77

a) Assignment

b) Less than

c) Equality

d) Greater than

17. Which logical operator represents AND? 78

a) ||

b) !

c) &&

d) ==

18. The || operator is used for which logical operation? 79

a) OR

b) AND

c) NOT

d) Equality

19. What does the ! operator do? 80

a) Logical OR
b) Logical NOT

c) Logical AND

d) Relational equality

20. Operators that operate on a single operand are called: 81

a) Binary operators

b) Relational operators

c) Unary operators

d) Logical operators

21. Operators that operate on two operands are called: 82

a) Unary operators

b) Binary operators

c) Assignment operators

d) Arithmetic operators

22. What is the order in which operators are evaluated in an expression called?
83

a) Operator evaluation

b) Operator precedence

c) Operator association

d) Operator hierarchy

23. The \n escape sequence is used for: 84

a) A tab

b) A newline

c) A backspace

d) An alert

24. Which of the following is a correct syntax for using scanf() to read an integer?
85

a) scanf("%d", age);

b) scanf("%d", &age);

c) scanf("age");
d) scanf(age);

25. The getch() function is used to: 86

a) Print output

b) Read input

c) Get a character from the user

d) Assign a value

Short Questions (30):

1. What is the purpose of input/output (I/O) functions in C? 87

2. Define

printf() function. 88

3. How can you display the value of a variable using

printf()? 89

4. What is the purpose of format specifiers? 90

5. List the format specifiers for

int, float, and char data types. 91

6. Explain the working of

scanf() function. 92

7. What are the two main parts of a

scanf() function? 93

8. What is a statement terminator? Give an example. 94

9. What is an escape sequence? 95

10. Give two examples of escape sequences and their purpose. 96

11. Define operator.

12. What are assignment operators? Give an example. 97

13. List all the arithmetic operators. 98

14. What is the difference between / and % operators?

15. What are relational operators?


16. List the six relational operators. 99

17. Differentiate between the assignment operator (

=) and the equal to operator (==). 100

18. What are logical operators?

19. List the three logical operators. 101

20. Differentiate between a

unary operator and a binary operator. 102

21. What is

operator precedence? 103

22. How is the value of an expression calculated based on operator precedence? 104

23. What is the output of the following C code snippet?

printf("I am a student of class 10"); 105

24. What is the use of

getch() function? 106

25. Explain why

printf("age"); does not display the value of the variable age. 107

26. What does

printf("My age is %d and my height is %f", age, height); do? 108

27. When is a logical operator used?

28. What is a "statement terminator"?

29. What is the function of \t escape sequence?

30. How would you read a character from the user and store it in a variable named

grade? 109

Long Questions (6):

1. Explain the purpose and usage of

printf() and scanf() functions with the help of examples. 110


2. What are format specifiers? Discuss their role in input and output functions.
Explain with examples. 111

3. What are arithmetic and relational operators? Explain each category with
examples. 112

4. Differentiate between unary and binary operators and logical operators. Explain
the function of each with examples. 113

5. What is operator precedence? Explain how it affects the evaluation of


expressions in C language with a relevant example. 114

6. Write a C program that takes two integer numbers from the user and displays
their sum, difference, product, and division on the screen.

Chapter 3

MCQs (25):

1. Which of the following is a selection statement? 115

a) for

b) if-else

c) while

d) do-while

2. The if statement allows a program to make a decision based on a: 116

a) Loop

b) Variable

c) Condition

d) Function

3. What is the keyword used for a simple selection statement in C? 117

a) else

b) if

c) switch

d) for
4. In an if-else statement, if the condition is true, which block of code is
executed? 118

a) The else block

b) The if block

c) Both blocks

d) Neither block

5. When does the else block of an if-else statement get executed? 119

a) When the condition is true

b) When the condition is false

c) Every time

d) Only when there is an error

6. A selection statement that contains another selection statement is called a:


120

a) Simple if statement

b) Nested if-else structure

c) for loop

d) switch statement

7. What is the purpose of using a control statement? 121

a) To perform arithmetic operations

b) To control the flow of execution in a program

c) To declare variables

d) To define functions

8. Which of the following is not a type of control statement? 122

a) Selection

b) Repetition

c) Sequence

d) Initialization

9. The if statement is used to execute a block of code only if a specific


condition is: 123
a) False

b) True

c) Undefined

d) Null

10. What is the difference between a simple if statement and an if-else statement?

a) The if statement has an else block.

b) The if-else statement executes code when the condition is false.

c) The if statement is used for loops.

d) There is no difference.

11. In a nested if-else structure, the inner if statement is dependent on the condition
of the:

a) outer else statement

b) outer if statement

c) inner else statement

d) compiler

12. What is the output of the following code if x is 10 and y is 5? if (x > y) { printf("x is
greater"); } else { printf("y is greater"); }

a) x is greater

b) y is greater

c) x is smaller

d) y is smaller

13. What is the output of the following code if age is 18? if (age >= 18) {
printf("Adult"); }

a) Adult

b) Nothing

c) age is an adult

d) Adult or not

14. In if-else statements, the code blocks are enclosed in:

a) () parentheses
b) [] brackets

c) {} curly braces

d) <> angle brackets

15. Conditional logic primarily deals with:

a) Repetitive tasks

b) Making decisions

c) Storing data

d) Defining functions

16. What does an if-else statement provide?

a) A single path of execution

b) A loop

c) Two alternative paths of execution

d) A function

17. Which of the following is a valid if statement?

a) if (x = 5)

b) if (x == 5);

c) if (x == 5)

d) if x == 5

18. The else keyword is optional with which statement?

a) if

b) for

c) while

d) switch

19. What happens if the condition in a simple if statement is false?

a) The program stops.

b) The code inside the if block is skipped.

c) An error is generated.

d) The program goes into an infinite loop.


20. A nested if-else structure can be used to handle:

a) A single condition

b) Two conditions

c) Multiple conditions

d) No conditions

21. Which operator is commonly used in if statements to compare values?

a) +

b) =

c) ==

d) &&

22. The code block of a simple if statement is executed when the given condition is
evaluated to:

a) 0

b) 1

c) True

d) False

23. What is a "control statement"?

a) A statement that controls the flow of a program.

b) A statement used to declare variables.

c) A statement used to define functions.

d) A statement used to perform calculations.

24. How are if-else and if statements classified?

a) as repetition statements

b) as selection statements

c) as jump statements

d) as loop statements

25. What is the primary difference between if and if-else statements in C


programming?

a) if statements always execute the code block, while if-else statements do not.
b) if statements provide a single path of execution, while if-else statements provide a
choice between two paths based on a condition.

c) if-else statements can be nested, while if statements cannot.

d) if statements are used for true conditions, while if-else statements are for false
conditions.

Short Questions (30):

1. What is the main purpose of control statements? 124

2. What are

selection statements? 125

3. Explain the basic function of an

if statement. 126

4. What is the syntax of a simple if statement?

5. When is the code block inside an

if statement executed? 127

6. Explain the function of an

if-else statement. 128

7. When is the

else part of an if-else statement executed? 129

8. Give an example of an if-else statement.

9. What is a

nested if-else structure? 130

10. Provide an example of a simple if statement.

11. How does a nested if-else structure differ from a simple if-else statement?

12. How can selection statements control the flow of a program?

13. What happens if the condition of an if statement is 0?

14. What happens if the condition of an if statement is non-zero?

15. What are the logical operators often used in if statements?

16. How can a programmer use a series of if-else if-else statements?


17. Write a short C program that checks if a number is positive or negative.

18. Write a short C program that checks if a person is eligible to vote (age >= 18).

19. What is the output of the following code if x=5? if(x==5) printf("Equal"); else
printf("Not Equal");

20. What is the output of the following code if x=10? if(x<5) printf("Less"); else
printf("Greater");

21. What does the term "conditional logic" refer to?

22. In a nested if-else statement, to which if does an else belong?

23. Write a code snippet to check if a number is even or odd.

24. How can multiple conditions be combined within a single if statement?

25. Explain the importance of curly braces {} in if-else statements.

26. What does if(a > 0 && a < 10) check for?

27. Write a program to check if a character is a vowel or a consonant.

28. What is the purpose of the else keyword?

29. Differentiate between control statements and selection statements.

30. What will be the output if x=5 and y=10 in if (x > y) { printf("x > y"); } else { printf("y
> x"); }?

Long Questions (6):

1. What are selection statements? Explain the working of

if and if-else statements with the help of syntax and examples. 131

2. Explain the concept of nested if-else structures. Provide a detailed example to


illustrate its usage. 132

3. Differentiate between a simple

if statement and an if-else statement, highlighting the scenarios where each is used. 133

4. Write a C program that takes a student's marks as input and prints their grade (A,
B, C, D, or F) based on a given grading scheme using if-else if-else structure.

5. Explain the concept of conditional logic and its importance in programming.


Write a C program that checks if a given year is a leap year.
6. Write a comprehensive C program that takes two numbers and an operator (+, -,
*, /) from the user and performs the corresponding calculation using if-else if
statements.

Chapter 4

MCQs (25):

1. What is an array? 134

a) A collection of different data types

b) A single variable

c) A collection of similar data types stored in contiguous memory locations

d) A function

2. The elements of an array are accessed using an index which starts from: 135

a) 1

b) 0

c) -1

d) 2

3. What is array declaration? 136

a) Assigning values to array elements

b) Giving a name and size to an array

c) Accessing array elements

d) Creating a loop

4. What is the syntax for initializing an array? 137

a) data_type array_name[size];

b) data_type array_name[size] = {value1, value2, ...};

c) data_type array_name;

d) data_type array_name[] = {value1, value2, ...};

5. A loop structure is used to execute a block of code: 138

a) once
b) repeatedly

c) only if a condition is true

d) at the end of the program

6. The for loop is composed of which three parts? 139

a) Start, end, and condition

b) Initialization, condition, and increment/decrement

c) Declaration, initialization, and execution

d) Start, middle, and end

7. The initialization part of a for loop is executed: 140

a) at every iteration

b) only once

c) at the end of the loop

d) when the condition is false

8. A loop inside another loop is called a: 141

a) Simple loop

b) Infinite loop

c) Nested loop

d) Function loop

9. In C, arrays are a type of: 142

a) Loop structure

b) Data structure

c) Selection statement

d) Function

10. The for loop is a repetition structure that is used when the number of iterations
is:

a) unknown

b) infinite

c) a variable
d) known

11. How can you access the third element of an array named marks?

a) marks[3]

b) marks(3)

c) marks[2]

d) marks(2)

12. Which of the following is an example of array initialization? 143

a) int arr[5];

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

c) arr[0] = 10;

d) int arr[];

13. What is a "loop"?

a) A way to store multiple values.

b) A way to make a decision.

c) A way to repeat a block of code.

d) A way to organize data.

14. The for loop is also known as a(n):

a) Entry-controlled loop

b) Exit-controlled loop

c) Infinite loop

d) Unconditional loop

15. What happens if the loop condition in a for loop is always true?

a) The loop terminates.

b) The program skips the loop.

c) An error is generated.

d) The loop becomes an infinite loop.

16. What does i++ do in the for loop for(i=0; i<10; i++)?

a) Initializes i to 10
b) Checks if i is less than 10

c) Increments the value of i by 1

d) Declares a variable i

17. What is the purpose of using loops with arrays?

a) To declare an array

b) To initialize a single element

c) To access and process each element of the array

d) To change the size of the array

18. Which part of the for loop is optional?

a) Initialization

b) Condition

c) Increment/decrement

d) All parts are optional.

19. How can you declare an array of size 10 to store integers?

a) int arr[10];

b) int arr[10];

c) int arr(10);

d) int arr;

20. What is the output of the following for loop? for(i=0; i<3; i++) { printf("%d ", i); }

a) 1 2 3

b) 0 1 2

c) 0 1 2 3

d) 1 2

21. The values of array elements are stored in:

a) random memory locations

b) contiguous memory locations

c) the hard drive

d) a register
22. What is the name given to the first element of an array?

a) array[1]

b) array[0]

c) array[first]

d) array[last]

23. How do you declare an array without specifying its size?

a) int arr[];

b) int arr;

c) int arr[] = {};

d) int arr;

24. A loop structure that is composed of an initialization, a condition and an


increment/decrement is:

a) while loop

b) do-while loop

c) for loop

d) switch statement

25. The loop body of a nested loop is executed:

a) only once

b) at every iteration of the outer loop

c) at every iteration of the inner loop

d) before the outer loop

Short Questions (30):

1. What is a

data structure? 144

2. Define an

array. 145

3. How is an array declared and initialized? 146


4. How are individual elements of an array accessed? 147

5. How can variables be used as array indexes? 148

6. What is a

loop structure? 149

7. What are the three main parts of a

for loop? 150

8. Explain the flow of execution of a

for loop. 151

9. What is a

nested loop? 152

10. Give an example of a nested for loop.

11. How can you find the sum of all elements in an array using a loop?

12. Explain the use of a

for loop with an array. 153

13. Write a program to print the first five even numbers using a for loop.

14. What will be the output of for(i=5; i>0; i--) { printf("%d ", i); }?

15. What is

array initialization? 154

16. How does an

array store data in memory? 155

17. How can you declare an array of size 5 to store float values?

18. What is the size of the array int a[] = {1, 2, 3};?

19. Write a program to take 5 integers from the user and store them in an array.

20. What is the difference between

array declaration and array initialization? 156

21. When should you use a for loop?

22. What is the role of the loop condition in a

for loop? 157


23. What happens if you try to access an array element with an index out of its
bounds?

24. How would you print the elements of an array in reverse order?

25. What is the purpose of the increment/decrement part of a loop? 158

26. Give an example of

using variables as array indexes. 159

27. What is the purpose of the loop body?

28. How is the general structure of a loop described? 160

29. What is the difference between a loop and a conditional statement?

30. How would you calculate the average of numbers in an array?

Long Questions (6):

1. What is an array? Explain

array declaration, initialization, and accessing array elements with the help of
examples. 161

2. What are loop structures? Explain the general syntax and working of a

for loop with an example. 162

3. Differentiate between array declaration and initialization and accessing array


elements. Provide a comprehensive C program that declares, initializes, and
then prints the elements of an array.

4. Explain the concept of nested loops. Write a C program that uses nested loops to
print a pattern (e.g., a right-angled triangle of asterisks). 163

5. Write a comprehensive C program that declares an array of integers, takes input


from the user to fill the array, and then finds and prints the largest and smallest
numbers from that array.

6. What is the relationship between loops and arrays? Explain with the help of a C
program that uses a loop to take input for an array and another loop to display
the content of the array. 164

Chapter 5
MCQs (25):

1. A function is a block of code designed to perform a particular: 165

a) Variable declaration

b) Task

c) Loop

d) Conditional check

2. The use of functions helps in making a program: 166

a) Longer and more complex

b) More difficult to read

c) Modular and reusable

d) Slower to execute

3. What is the purpose of a function call? 167

a) To define the function

b) To execute the code block of the function

c) To declare a variable

d) To return a value

4. The C language library contains a number of predefined functions such as:


168

a) if()

b) main()

c) while()

d) printf()

5. Which of the following is an advantage of using functions? 169

a) It makes the code more repetitive.

b) It reduces the readability of the program.

c) It makes the code reusable.

d) It increases the size of the program.

6. The structure of a function consists of a function header and a function body.


The function header includes:
170

a) The code to be executed.

b) The return type, function name, and parameter list.

c) The variables and constants.

d) The loop structures.

7. What is the part of a function where all the statements to be executed are
written? 171

a) Function header

b) Function body

c) Function call

d) Return type

8. Which of the following is an example of a user-defined function?

a) printf()

b) scanf()

c) add_numbers()

d) main()

9. The return statement in a function is used to:

a) Stop the program execution.

b) Return a value to the calling part of the program.

c) Print a message.

d) Declare a variable.

10. A function that does not return any value has a return type of:

a) int

b) float

c) char

d) void

11. A function prototype is also known as a:

a) Function definition
b) Function declaration

c) Function call

d) Function body

12. What does the parameter list of a function contain?

a) The names of variables to be passed.

b) The data types and names of the variables to be passed.

c) The values of the variables.

d) The return type.

13. Which statement is used to define a function?

a) A function call.

b) A function prototype.

c) The function header and function body.

d) The return statement.

14. When a function is called, the program's control is transferred to:

a) the end of the program

b) the calling function

c) the body of the called function

d) the header of the called function

15. The main() function is an example of a:

a) Predefined function

b) User-defined function

c) Both a) and b)

d) None of the above

16. In a C program, a function must be declared before it is:

a) Defined

b) Called

c) Used in a loop

d) Used with variables


17. Which of the following describes the correct order of elements in a function's
header?

a) function_name return_type (parameter_list)

b) return_type function_name (parameter_list)

c) (parameter_list) return_type function_name

d) function_name (parameter_list) return_type

18. A function definition includes:

a) only the function header

b) only the function body

c) the function header and function body

d) the function call

19. What does a function signature include?

a) Only the function name

b) The function name and parameter list

c) The function name, parameter list, and return type

d) Only the return type

20. Which of the following is not a benefit of using functions?

a) Code reusability

b) Improved readability

c) Increased code complexity

d) Easier debugging

21. What is the purpose of the return keyword in a function?

a) To end the function and return a value to the caller.

b) To declare a variable.

c) To print a message.

d) To define a new function.

22. The two main types of functions are:

a) predefined and user-defined


b) main and sub

c) return and void

d) header and body

23. What is another term for predefined functions?

a) Library functions

b) Custom functions

c) Main functions

d) Void functions

24. When is a function definition typically placed in a C program?

a) Before the main() function

b) After the main() function

c) Both before and after main() are possible

d) Inside the main() function

25. If a function is defined to take two integer parameters, what is the correct way to
call it with values 5 and 10?

a) my_function(5, 10);

b) call my_function(5, 10);

c) my_function(int 5, int 10);

d) my_function[5, 10];

Short Questions (30):

1. What is a function in programming? 172

2. What are the advantages of using functions? 173

3. What are the two types of functions? 174

4. What is the structure of a function? 175

5. What does the

function header include? 176

6. What is a
function body? 177

7. What is

function definition? 178

8. How does a function return a value?

9. What is a void function?

10. What is a function prototype?

11. Give an example of a function header.

12. How do you call a function? 179

13. What is the purpose of parameters in a function?

14. How does a function help in debugging a program?

15. What does int add(int a, int b); represent?

16. What is the purpose of the

main() function? 180

17. What is the difference between a function declaration and a function definition?

18. How can functions make a program more readable?

19. What is a function signature?

20. Write a function header for a function named calculateArea that takes two
integer parameters, length and width, and returns an integer.

21. What happens when a function is called?

22. What is the difference between formal parameters and actual parameters?

23. What is the purpose of the return statement in a function?

24. Explain the concept of modular programming.

25. What is the purpose of the printf() function in the context of Chapter 5?

26. How do functions relate to code reusability?

27. Write a simple void function that prints "Hello from the function".

28. Can a function call another function?

29. How can a function be defined without any parameters?

30. What is the difference between a library function and a user-defined function?
Long Questions (6):

1. What is a function? Explain the advantages of using functions in C programming.


181

2. Explain the structure of a function. What are the key components of a function
header and a function body? Provide an example of a simple function definition.
182

3. Differentiate between predefined (library) and user-defined functions with


suitable examples.

4. Write a comprehensive C program that defines a function to calculate the


factorial of a number. The program should take an integer as input from the user,
call the factorial function, and then display the result.

5. Explain the concepts of function declaration, function definition, and function


call. Provide a C program to demonstrate these concepts with an example of a
function that takes two integers as input and returns their sum.

6. What is the role of the main() function in a C program? Explain how it serves as
the entry point for program execution and how it can call other functions. 183

You might also like