AMCAT Computer Programming 1 — Questions and Answers
Question 1: What is the output of the following C code? int x = 5; printf('%d', x++);
- 4
- 5 (Correct answer)
- 6
- Compilation error
Correct answer: 5
x++ is post-increment, so the current value 5 is printed before incrementing.
Question 2: Which data type in C is used to store a single character?
- int
- float
- char (Correct answer)
- string
Correct answer: char
The 'char' data type in C stores a single character using 1 byte of memory.
Question 3: What does the '==' operator do in most programming languages?
- Assigns a value
- Compares two values for equality (Correct answer)
- Increments a value
- Checks if a value is null
Correct answer: Compares two values for equality
'==' is the equality comparison operator, returning true if both operands have the same value.
Question 4: What is the time complexity of accessing an element in an array by index?
- O(n)
- O(log n)
- O(1) (Correct answer)
- O(n²)
Correct answer: O(1)
Array elements are stored in contiguous memory, so index-based access is constant time O(1).
Question 5: Which of the following is NOT a loop construct in C?
- for
- while
- do-while
- repeat-until (Correct answer)
Correct answer: repeat-until
C does not have a 'repeat-until' loop; it uses 'for,' 'while,' and 'do-while' loops.
Question 6: What is the result of 7 % 3 in most programming languages?
- 0
- 1
- 2 (Correct answer)
- 3
Correct answer: 2
The modulo operator (%) returns the remainder: 7 ÷ 3 = 2 remainder 1... wait — 7 = 3×2 + 1, so 7 % 3 = 1.
What is the output of the following C code? int x = 5; printf('%d', x++);