MCQ Bank
In C++, atof () function is used to convert ________.
- A) Character string to long integer
- B) Character string to float
- C) Character string to short
- D) Character string to integer
Which of the following is not a file opening mode?
- A) ios::ate
- B) ios::nocreate
- C) ios::in
- D) ios::trunc
To create an output file stream, we must declare the stream to be of class.
- A) ifstream
- B) ofstream
- C) iostream
- D) cstream
What will be the output of the following code? #include <iostream> #include <cstring> using namespace std; int main() { char s1[20] = "Hello"; char s2[] = "World"; strcpy(s1, s2); cout << s1; return 0; }
- A) World
- B) Hello
- C) HelloWorld
- D) Undefined
Suppose we have declared a two-dimensional array “multi”. To access its elements using pointer, we should use referencing like ________.
- A) **multi
- B) *multi
- C) *multi + 1
- D) multi
What will happen if you run the following code when "data.txt" does not exist? #include <iostream> #include <fstream> using namespace std; int main() { ifstream file("data.txt"); if (!file) { cout << "File not found!" << endl; } return 0; }
- A) It will throw an exception.
- B) It will print File not found!.
- C) It will do nothing.
- D) It will create "data.txt".
In C++, atoi () function is used to convert _______.
- A) Character string to long integer
- B) Character string to integer
- C) Character string to double
- D) Character string to float
To perform I/O operations on file, we must use _____________ header file.
- A) cstream
- B) fstream
- C) hstream
- D) istream
In C++, a file can be opened for reading by using the _____ function.
- A) read()
- B) open()
- C) open_file()
- D) write()
What will be the output of the following code? int main (int argc, char **argv) { cout<<argc; }
- A) 2
- B) Null
- C) 0
- D) 1
In C++, a sequence of objects having the same type, is called ________.
- A) Operator
- B) Array
- C) Function
- D) Stack
What will be the output of the following code? int main() { int a[4]={1,2,3,4}; cout<< a[2]; }
- A) 1
- B) 2
- C) 3
- D) 4
What is the output of the following code snippet? int a = 5; int *ptr = &a; *ptr = 10; cout << a;
- A) 5
- B) 0
- C) 10
- D) Undefined
In C++, to get the value stored at a memory address, we use the _______ operator.
- A) dereferencing
- B) bitwise
- C) arithmetic
- D) logical
What will be the output of the following code? int main() { int x = 5; int * ptr = &x; *ptr + 1; cout << (*ptr)++; }
- A) 8
- B) 7
- C) 6
- D) 5
Identify the invalid option.
- A) int *pi = 0;
- B) int i; double* dp = &i;
- C) int *ip;
- D) char s, *sp = 0;
Which of the following option gives the [value] stored at the address pointed to by the pointer "ptr"?
- A) Value(ptr)
- B) ptr
- C) *ptr
- D) &ptr
What will be the output of the following code? int main(){ char str[] = "Hello World"; cout<<str[4]; return 0; }
- A) H
- B) l
- C) W
- D) o
In C++, a one-dimensional array inside a one-dimensional array is called _________.
- A) Three-dimensional array
- B) Multi-casting array
- C) Two-dimensional array
- D) One-dimensional array
In C++, pointer can be initialized with
- A) Hash(#)
- B) Semicolon(;)
- C) Dot(.)
- D) Null