21–30: Functions and Arrays
-
Which is the correct syntax to define a function in C++?
a)function name() {}
b)void name() {}
c)def name():
d)fun name() {}
Answer: b -
Which is the correct way to pass a variable by reference?
a)void func(int x)
b)void func(int* x)
c)void func(int &x)
d)void func(ref x)
Answer: c -
What is the index of the first element in an array?
a) 1
b) 0
c) -1
d) It depends
Answer: b -
What is the correct way to declare a 1D array of 10 integers?
a)int arr[10];
b)int[10] arr;
c)arr int[10];
d)array[10] int;
Answer: a -
What happens if you access an array out of bounds in C++?
a) Compiler error
b) Runtime error
c) Undefined behavior
d) Segmentation fault
Answer: c -
Which of these is not a valid return type of a function in C++?
a)void
b)int
c)array
d)char
Answer: c -
Which of the following denotes function overloading?
a) Functions with same name, different parameters
b) Functions with different names
c) Functions inside classes
d) None
Answer: a -
What does
sizeof(arr)
return in C++ ifarr
is an array of 5 integers?
a) 5
b) 10
c) 20 (if int = 4 bytes)
d) Compiler error
Answer: c -
What is recursion?
a) A function that calls itself
b) A function that loops
c) A loop inside a function
d) None
Answer: a -
Which header file is required for using mathematical functions like
sqrt()
?
a)<math.h>
b)<cmath>
c) Both
d) None
Answer: c
0 Comments