AMCAT Computer Programming 2 — Questions and Answers
Question 1: What is the result of 7 % 3 in C?
- 0
- 1 (Correct answer)
- 2
- 3
Correct answer: 1
7 divided by 3 gives quotient 2 and remainder 1, so 7 % 3 = 1.
Question 2: Which keyword is used to exit a loop prematurely in C/C++?
- exit
- stop
- break (Correct answer)
- return
Correct answer: break
The 'break' statement immediately terminates the nearest enclosing loop or switch statement.
Question 3: In object-oriented programming, which concept allows a class to inherit properties from another class?
- Encapsulation
- Polymorphism
- Abstraction
- Inheritance (Correct answer)
Correct answer: Inheritance
Inheritance allows a child class to acquire properties and behaviors of a parent class.
Question 4: What is the output of: print(type(3.14)) in Python?
- <class 'int'>
- <class 'float'> (Correct answer)
- <class 'double'>
- <class 'decimal'>
Correct answer: <class 'float'>
3.14 is a floating-point literal in Python, so its type is 'float'.
Question 5: Which of the following is a valid way to declare a variable in Java?
- var x = 10;
- int x = 10; (Correct answer)
- x = 10;
- integer x = 10;
Correct answer: int x = 10;
In Java, variables must be declared with explicit data types like 'int x = 10;' (though 'var' is valid from Java 10+).
Question 6: What does HTML stand for?
- HyperText Markup Language (Correct answer)
- High Transfer Markup Language
- HyperText Management Language
- Hybrid Text Markup Language
Correct answer: HyperText Markup Language
HTML stands for HyperText Markup Language, the standard language for creating web pages.
What is the result of 7 % 3 in C?