C Programming Short Questions with Answers
(Units 1–5)
Unit 1
Q: 1. What is source code?
Ans: The human-readable program written by a programmer in a high-level language (like C).
Q: 2. Define an algorithm.
Ans: A step-by-step procedure to solve a problem.
Q: 3. Which symbol in a flowchart is used for input/output?
Ans: Parallelogram.
Q: 4. What is a variable?
Ans: A named memory location that stores data which can be changed during execution.
Q: 5. Define a constant.
Ans: A fixed value that cannot be changed during program execution.
Q: 6. Give an example of a valid identifier in C.
Ans: Example: value_1 or myVar.
Q: 7. Can a variable name start with a digit?
Ans: No, variable names cannot start with a digit.
Q: 8. What is a keyword in C?
Ans: A reserved word in C with a predefined meaning (e.g., int, if, return).
Q: 9. Name two numeric data types in C.
Ans: int, float.
Q: 10. What is an interpreter?
Ans: A program that translates and executes code line by line.
Q: 11. What is a compiler?
Ans: A program that translates the whole source code into machine code before execution.
Unit 2
Q: 1. What is the purpose of the #include directive in C?
Ans: It is used to include header files in a program.
Q: 2. Name two common header files used for input/output in C.
Ans: , .
Q: 3. Name one function used to read a single character from the keyboard without echoing it on
the screen.
Ans: getch().
Q: 4. What does the modulus operator (%) do?
Ans: It returns the remainder of a division.
Q: 5. What is the use of the sizeof() operator?
Ans: It gives the size (in bytes) of a variable or data type.
Q: 6. What does the ternary operator ?: do?
Ans: It is a conditional operator that selects one of two values depending on a condition.
Q: 7. Which function returns the absolute value of an integer?
Ans: abs().
Q: 8. What does #define do in a C program?
Ans: It defines symbolic constants or macros.
Q: 9. Which function returns the length of a string?
Ans: strlen().
Unit 3
Q: 1. What is the syntax of a simple if statement?
Ans: if (condition) { statements; }
Q: 2. What happens when the condition in an if statement is false?
Ans: The statements inside the if block are skipped.
Q: 3. How does an if...else statement work?
Ans: If condition is true, the if block runs; otherwise the else block runs.
Q: 4. Can an if statement be used without an else?
Ans: Yes.
Q: 5. What is a nested if statement?
Ans: An if statement inside another if statement.
Q: 6. What happens when none of the cases match in a switch statement and there is no default
case?
Ans: Nothing executes, control moves outside switch.
Q: 7. Can you nest switch statements inside another switch?
Ans: Yes, switch can be nested.
Q: 8. What type of expressions can be used in if conditions?
Ans: Boolean or relational/logical expressions.
Q: 9. Can the if statement evaluate more than one condition at a time?
Ans: Yes, using logical operators (&&, ||).
Q: 10. What keyword ends the else if ladder?
Ans: else.
Unit 4
Q: 1. What will happen if the while loop condition never becomes false?
Ans: Infinite loop.
Q: 2. Which loop guarantees execution of the loop body at least once?
Ans: do...while loop.
Q: 3. What is the difference between break and continue statements?
Ans: break ends the loop, continue skips current iteration and moves to next.
Q: 4. Can you use continue in a do...while loop?
Ans: Yes.
Q: 5. Write one example where a nested for loop might be useful.
Ans: Printing multiplication tables.
Q: 6. What is the purpose of the goto statement?
Ans: Provides unconditional jump to a labeled statement.
Q: 7. Can goto be used for iteration?
Ans: Yes, but not recommended (bad practice).
Q: 8. How is the do...while loop different from the while loop?
Ans: do...while executes at least once, while loop may not execute at all.
Q: 9. Write the syntax of a for loop.
Ans: for(initialization; condition; increment/decrement) { statements; }
Q: 10. What are the three parts of a for loop?
Ans: Initialization, Condition, Increment/Decrement.
Unit 5
Q: 1. What does \n represent in a string?
Ans: Newline character.
Q: 2. How does \t affect the output of a string?
Ans: Inserts a horizontal tab space.
Q: 3. What is linear search in the context of arrays?
Ans: Sequentially checking each element to find a match.
Q: 4. What is the basic idea of bubble sort?
Ans: Repeatedly swapping adjacent elements if they are in the wrong order.
Q: 5. How does selection sort differ from bubble sort?
Ans: Selection sort selects the smallest element and places it in order, bubble sort swaps adjacent
elements.
Q: 6. What is an array in C?
Ans: A collection of elements of the same type stored in contiguous memory.
Q: 7. How do you declare an integer array of size 10?
Ans: int arr[10];
Q: 8. What is the index of the first element in an array?
Ans: 0
Q: 9. How is memory allocated for arrays in C?
Ans: Contiguously (sequential blocks of memory).
Q: 10. What is the purpose of the null character \0 in a character array?
Ans: It marks the end of a string.