0% found this document useful (0 votes)
9 views3 pages

CPT Test

The document contains a series of programming questions and answers related to Python and C++. It covers topics such as function output, data structures, comparison operations, pointers, compilers vs interpreters, valid identifiers, and directives. Each question is followed by the correct answer, providing a quick reference for programming concepts.

Uploaded by

taiye.m2203773
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)
9 views3 pages

CPT Test

The document contains a series of programming questions and answers related to Python and C++. It covers topics such as function output, data structures, comparison operations, pointers, compilers vs interpreters, valid identifiers, and directives. Each question is followed by the correct answer, providing a quick reference for programming concepts.

Uploaded by

taiye.m2203773
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
You are on page 1/ 3

1. 1. What is the output of the following code?

```python
def func(x, y=[]):
y.append(x)
return y

print(func(1))
print(func(2))
```
a) [1] [2]
b) [1, 2] [1, 2]
c) [1] [1, 2]
d) [1, 2] [2]

Answer: c) [1] [1, 2]

2. 2. Which data structure does `set()` represent and what is its main property?
a) List; ordered
b) Dictionary; key-value pairs
c) Set; unordered with no duplicates
d) Tuple; immutable

Answer: c) Set; unordered with no duplicates

3. 3. What will `print(3 == 3.0)` output in Python?


a) True
b) False
c) Error
d) None

Answer: a) True

4. What will be the output of the following code?


```cpp
int a = 5;
int b = 10;
cout << a++ + ++b;

Answer: c) 17
5. Which of these is the correct way to define a pointer to an integer in C++?
a) int* p;
b) pointer<int> p;
c) int p*;
d) int pointer p;

Answer: a) int* p;

6. What is the main difference between a compiler and an interpreter?


a) Compiler translates code line-by-line, interpreter does it all at once
b) Interpreter translates code line-by-line, compiler does it all at once
c) Both are the same
d) Compiler is for Python, interpreter is for C++

Answer: b) Interpreter translates code line-by-line, compiler does it all at once

7. Which of the following is a valid identifier in Python?


a) 1value
b) value_1
c) value-1
d) def

Answer: b) value_1

8. What is the purpose of the #include directive in C++?


a) It runs a loop
b) It includes libraries or header files
c) It comments out code
d) It defines a variable

Answer: b) It includes libraries or header files

9. In Python, which data type is immutable?


a) List
b) Dictionary
c) Tuple
d) Set

Answer: c) Tuple
10. Which keyword is used in C++ to create a constant value?
a) const
b) final
c) static
d) immutable

Answer: a) const

You might also like