MCQ's

 

1. Is Python case sensitive when dealing with identifiers?
a) yes
b) no
c) machine dependent
d) none of the mentioned

View Answer

Answer: a
Explanation: Case is always significant.

2. Which of the following is an invalid variable?
a) my_string_1
b) 1st_string
c) foo
d) _

View Answer

Answer: a
Explanation: eval can be used as a variable.

3. Which of the following is not a keyword?
a) eval
b) assert
c) non local
d) pass

View Answer

Answer: a
Explanation: eval can be used as a variable.

4. All keywords in Python are in
a) lower case
b) UPPER CASE
c) Capitalized
d) None of the mentioned

View Answer

Answer: d
Explanation: True, False and None are capitalized while the others are in lower case.

5. Which of the following cannot be a variable?
a) __init__
b) in
c) it
d) on

View Answer

Answer: b
Explanation: in is a keyword.

6. All keywords in Python are in
a) lower case
b) UPPER CASE
c) Capitalized
d) None of the mentioned

View Answer

Answer: d
Explanation: True, False and None are capitalized while the others are in lower case.

7. Which is the correct operator for power(xy)?
a) X^y
b) X**y
c) X^^y
d) None of the mentioned

View Answer

Answer: b
Explanation: In python, power operator is x**y i.e. 2**3=8.

8. What is the answer to this expression, 22 % 3 is?
a) 7
b) 1
c) 0
d) 5

View Answer

Answer: b
Explanation: Modulus operator gives the remainder. So, 22%3 gives the remainder, that is, 1.

9. What is the output of this expression, 3*1**3?
a) 27
b) 9
c) 3
d) 1

View Answer

Answer: c
Explanation: First this expression will solve 1**3 because exponential has higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3.

10. What data type is the object below ?
L = [1, 23, ‘hello’, 1].
a) list
b) dictionary
c) array
d) tuple

View Answer

Answer: a
Explanation: List data type can store any values within i

11. In order to store values in terms of key and value we use what core data type?
a) list
b) tuple
c) class
d) dictionary

View Answer

Answer: d
Explanation: Dictionary stores values in terms of keys and values.

1. C99 standard guarantees uniqueness of ____ characters for internal names.
a) 31
b) 63
c) 12
d) 14

View Answer

Answer: b
Explanation: ISO C99 compiler may consider only first 63 characters for internal names.

2. Which of the following is not a valid variable name declaration?
a) int __a3;
b) int __3a;
c) int __A3;
d) None of the mentioned

View Answer

Answer: d
Explanation: all varaibles are following the rules for declaration of identifier

3. Which of the following is not a valid variable name declaration?
a) int _a3;
b) int a_3;
c) int 3_a;
d) int _3a

View Answer

Answer c
Explanation: for an identifier it can't start with an number

4. All keywords in C are in
a) LowerCase letters
b) UpperCase letters
c) CamelCase letters
d) None of the mentioned

View Answer

Answer a
Explanation: as keywords in c is an case sensitive

5. Which of the following is not a valid C variable name?
a) int number;
b) float rate;
c) int variable_count;
d) int $main;

View Answer

Answer: d
Explanation: Since only underscore and no other special character is allowed in a variable name, it results in an error.

6. Which of the following is true for variable names in C?
a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length

View Answer

Answer: c
Explanation: According to the syntax for C variable name, it cannot start with a digit.

7.Which is valid C expression?
a) int my_num = 100,000;
b) int my_num = 100000;
c) int my num = 1000;
d) int $my_num = 10000;

View Answer

Answer: b
Explanation: Space, comma and $ cannot be used in a variable name.

8.Which of the following is not a valid variable name declaration?
a) float PI = 3.14;
b) double PI = 3.14;
c) int PI = 3.14;
d) #define PI 3.14

View Answer

Answer: d
Explanation: #define PI 3.14 is a macro preprocessor, it is a textual substitution.

9. Which of the following cannot be a variable name in C?
a) volatile
b) true
c) friend
d) export

View Answer

Answer: a
Explanation: volatile is C keyword.

10.The format identifier ‘%i’ is also used for _____ data type.
a) char
b) int
c) float
d) double

View Answer

Answer: b
Explanation: Both %d and %i can be used as a format identifier for int data type.

11.Which data type is most suitable for storing a number 65000 in a 32-bit system?
a) signed short
b) unsigned short
c) long
d) int

View Answer

Answer: b
Explanation: 65000 comes in the range of short (16-bit) which occupies the least memory. Signed short ranges from -32768 to 32767 and hence we should use unsigned short.

12.Which of the following is a User-defined data type?
a) typedef int Boolean;
b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) struct {char name[10], int age};
d) all of the mentioned

View Answer

Answer: d
Explanation: typedef and struct are used to define user-defined data types.

13. What is the size of an int data type?
a) 4 Bytes
b) 8 Bytes
c) Depends on the system/compiler
d) Cannot be determined

View Answer

Answer: c
Explanation: The size of the data types depend on the system

14.Which is correct with respect to the size of the data types?
a) char > int > float
b) int > char > float
c) char < int < double
d) double > char > int

View Answer

Answer c
Explanation: char has less bytes than int and int has less bytes than double in any system

15. Which of the data types has the size that is variable?
a) int
b) struct
c) float
d) double

View Answer

Answer: b
Explanation: Since the size of the structure depends on its fields, it has a variable size

16. Which of the following statement is false?
a) Constant variables need not be defined as they are declared and can be defined later
b) Global constant variables are initialized to zero
c) const keyword is used to define constant values
d) You cannot reassign a value to a constant variable

View Answer

Answer: a
Explanation: Since the constant variable has to be declared and defined at the same time, not doing it results in an error.

17.Which of the following declaration is not supported by C?
a) String str;
b) char *str;
c) float str = 3e2;
d) Both String str; & float str = 3e2;

View Answer

Answer: a
Explanation: It is legal in Java, but not in C.

18.Which keyword is used to prevent any changes in the variable within a C program?
a) immutable
b) mutable
c) const
d) volatile

View Answer

Answer: c
Explanation: const is a keyword constant in C program.

19.Which of the following is not a pointer declaration?
a) char a[10];
b) char a[] = {‘1’, ‘2’, ‘3’, ‘4’};
c) char *str;
d) char a;

View Answer

Answer: d
Explanation: Array declarations are pointer declarations.

20.Which of the following statement is false?
a) A variable defined once can be defined again with different scope
b) A single variable cannot be defined with two different types in the same scope
c) A variable must be declared and defined at the same time
d) A variable refers to a location in memory

View Answer

Answer: c
Explanation: It is not an error if the variable is declared and not defined. For example â€" extern declarations.

21.A variable declared in a function can be used in main().
a) True
b) False
c) True if it is declared static
d) None of the mentioned

View Answer

Answer: b
Explanation: Since the scope of the variable declared within a function is restricted only within that function, so the above statement is false.

22. The name of the variable used in one function cannot be used in another function.
a) True
b) False
c) May be
d) None of the mentioned

View Answer

Answer: b
Explanation: Since the scope of the variable declared within a function is restricted only within that function, the same name can be used to declare another variable in another function.

mixpanel.track("Video play");