S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
SRI VASAVI COLLEGE, SFW, ERODE
340 C & C++ MCQ with ANSWERS
C Introduction (20), C Data Types, Operators and Expressions(25), Conditional
Statements & Looping(30), Arrays & Strings(15) ,Oops (40), C++ Fundamentals(30),
Constants & Data types(30), Decision Making & Looping(30), Operators(20),
Functions(20), Arrays Strings(30), Structures(10) & Pointer(20), File(30)
Prepare by
Drs. S.ANUSUYA, MCA., M.Phil.,Ph.D.,
ASSISTANT PROFESSOR & HEAD in COMPUER SCIENCE (AI & DS)
Sri Vasavi College (SFW), Erode
anuciaa@gmail.com
C INTRODUCTION
1. Who is the father of C language?
a) Steve Jobs b) James Gosling c) Dennis Ritchie d) Rasmus Lerdorf
2. In which year was C language developed?
a) 1962 b) 1978 c) 1979 d) 1972
3. All keywords in C are in ____________
a) LowerCase letters b) UpperCase letters c) CamelCase letters d) None
4. C language is a successor to which language?
a) Basic b) Cobol c) C++ d) B
4. C is a ___.
a) Low level language b) High level language c) Medium level language d) None above
5. How many keywords are there in C language?
a) 32 b)33 c)64 d) 18
6. C language is a ___.
a) Procedural oriented programming language b) General purpose programming language
c) Structured programming d) All of the above
7. Which is not a valid keyword in C language?
a) for b) while c) do-while d) switch
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
8. What is an identifier in C language?
a) An identifier is a combination of alphanumeric characters used for conditional and control
statements
b) An identifier is a combination of alphanumeric characters used for any variable, function,
label name
c) Both A and B d) None of the above
9. A C-style comment, simply surround the text with ___.
a) /* and */ b) // and // c) // d) /** and **/
10. Can we place comments between the statement to comments a part of the code?
a) Yes b) No
11. ___ is an informal name for ISO/IEC 9899:1999, a past version of the C programming language
standard?
a) C b) C++ c) C89 d) C99
12. In which version of C language, the C++ Style comment (//) are introduced?
a) C17 b) C18 c) C89 d) C99
13. The C source file is processed by the ___.
a) Interpreter b) Compiler c) Both Interpreter and Compiler d) Assembler
14. How many whitespace characters are allowed in C language?
a) 2 b) 3 c) 4 d) 5
15. How many punctuation characters are allowed in C language?
a) 29 b) 30 c) 31 d) 32
16. What is the extension of a C language source file?
a) .c b) .cpp c) .c99 d) .h
17. What is the extension of a C language header file?
a) .c b) .cpp c) .c99 d) .h
18. To develop which operating, C language was invented?
a) Linux b) Unix c) Android d) Mac
19. Does C language support object-oriented approach?
a) Yes b) No
20. Which is/are the disadvantage(s) of C language?
a) No Garbage Collection b) Inefficient Memory Management
c) Low level of abstraction d) Lack of Object Orientation e) All of the above
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
C DATA TYPES, OPERATORS AND EXPRESSIONS
1. Which are the fundamental data types in C?
a) char b) int c) float d) All of the above
2. How many byte(s) does a char type take in C?
a) 1 b) 2 c) 3 d) 4
3. For which type, the format specifier "%i" is used?
a) int b) char c) float d) double
4. What is the difference between float and double in C?
a) both are used for the same purpose
b) double can store just double value as compare to float value
c) double is an enhanced version of float and was introduced in C99
d) double is more precise than float and can store 64 bits
5. Which is the correct format specifier for double type value in C?
a) %d b) %f c) %lf d) %LF
6. The short type represents ___.
a) int b) float c) unsigned int d) short int
7. How many byte(s) does a short type take in C?
a) 1 b) 2 c) 3 d) 4
8. What is the correct syntax to declare a variable in C?
a) data_type variable_name; b) data_type as variable_name;
c) variable_name data_type; d) variable_name as data_type;
9. How many types of qualifiers are there in C language?
a) 2 b) 3 c) 4 d) 5
10. Which is/are the size qualifier(s) in C language?
a) short b) long c) double d) Both A. and B
31. Which is/are the sign qualifier(s) in C language?
a) signed b) unsigned c) long d) Both A. and B
12. Which is/are the type qualifier(s) in C language?
a) const b) volatile c) static d) Both A. and B
13. Which is correct with respect to the size of the data types in C?
a) char > int > float b) char < int < float
c) int < char < float d)int < chat > float
14. Which operator is used to find the remainder of two numbers in C?
a) / b) c) % d)
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
15. Which of the following is not an arithmetic expression?
a) x = 10 b) x /= 10 c) x %= 10 d) x != 10
16. Increment (++) and decrement (--) are the ___ operators in C?
a) Unary b) Binary c) Ternary d) None of the above
17. Which C keyword is used to extend the visibility of variables?
a) extend b) extends c) extern d) auto
18. What is the name of "&" operator in C?
a) Ampersand b) And c) Address of c) None of the above
19. 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
20. 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;
21. Which of the following cannot be a variable name in C?
a) volatile b) true c) friend d) export
22. What is short int in C programming?
a) The basic data type of C b) Qualifier
c) Short is the qualifier and int is the basic data type d) All of the mentioned
23. Functions in C Language are always _________
a) Internal b) External c) Both a & b ) External and Internal are not valid terms for functions
24. Which of the following is not a valid C variable name?
a) int number; b) float rate; c) int variable_count; d) int $main;
25. Which of the following is true for variable names in C?
a) Variable names cannot start with a digit b) Variable can be of any length
c) They can contain alphanumeric characters as well as special characters
d) Reserved Word can be used as variable name
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
C CONDITIONAL STATEMENTS & LOOPING
1. Which of the following are valid decision-making statements in C?
A) if b) switch c) nested if d) All of these
2. Decision making in the C programming language is ___.
a) Repeating the same statement multiple times
b) Executing a set of statements based on some condition
c) Providing a name of the block of code d) All of these
3. Which of the following is a true value in C programming?
a) 1 b) "includehelp" c) ! NULL d) All of these
4. Ternary operator in C programming is ___.
a) if-else-if b) ? : c) ? ; ? d) None of these
5. The if statement is a conditional statement?
a) True b) False
6. When the condition of if statement is false, the flow of code will ___.
a) go into the if block b) Exit the program
c) Continue the code after skipping the if block d) None of these
7. Which statement is required to execute a block of code when the condition is false?
a) for b) if c) else d) All of these
8. Can the else statement exist without the if statement in C?
a) Yes b) No
9. The if-elseif-else statement in C programming is used?
a) Create multiple conditional statements b) Return values
c) Loop in if-else block d) All of these
10. How many expressions can be checked using if...elseif...else statement?
a) 100 b) 1 c) Infinite d) None of these
11. Is it possible to nest if-else statements in C programming?
a) Yes b) No
12. Multiple values of the same variable can be tested using ___.
a) switch b) for c) Function d) All of these
13. Without a break statement in switch what will happen?
a) All cases will work properly b) Cases will fall through after matching the first check
c) Switch will throw error d) All of these
14. When all cases are unmatched which case is matched in a switch statement?
a) Default case b) First case c) No case d)None of these
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
15. Loops in C programming are used to ___.
Execute a statement based on a condition b) Execute a block of code repeatedly
c)Create a variable d) None of these
16. Which of these is an exit-controlled loop?
a) for b) if c) do...while d) while
17. Which statements are used to change the execution sequence?
a) Loop control statement b) Function statement
c) Conditional statement d) All of these
18. What will happen if the loop condition will never become false?
a) Program will throw an error b) Program will loop infinitely
c) Loop will not run d) None of these
19. Which of these statements is correct in case of while loop in C?
a) Executes the block till the condition become false b) Is an entry controlled loop
c) There might be condition when the loop will not execute at all d) All of these
20. Which loop executes the block a specific number of times?
a) while loop b) for loop c) do...while loop d) All of these
21. Which of the following parts of the for loop can be eliminated in C?
a) init b) condition c) increment d) All of these
22. When all parts of the for loop are eliminated, what will happen?
a) For loop will not work b) Infinite for loop c) Error d) None of these
23. When the condition of the do-while loop is false, how many times will it execute the code?
a) 0 b) 1 c) Infinite d) All of these
24. Can a loop be nested in C programming?
a) Yes b) No
25. The continue statment cannot be used with
a) for b) while c) do while d) switch
26. goto can be used to jump from main to within a function?
a) TRUE b) FALSE c) May Be d) Can't Say
27. Switch statement accepts.
a) int b) char c) long d) All of the above
28. Which loop is guaranteed to execute at least one time.
a) for b) while c) do while d) None of the above
29. do-while loop terminates when conditional expression returns?
a) One b) Zero c) Non – zero d) None of the above
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
30. Which of the following statement about for loop is true?
a) Index value is retained outside the loop
b) Index value can be changed from within the loop
c) Goto can be used to jump, out of the loop
d) All of these
STRINGS & ARRAYS
1. A string is terminated by ___.
a) Newline ('n') b) Null ('0') c) Whitespace d) None of the above
2. Which format specifier is used to read and print the string using printf() and scanf() in C?
a) %c b)%str c)%p d) %s
3. Which function is used to read a line of text including spaces from the user in C?
a) scanf() b) getc() c) fgets() d) All of the above
4. Which function is used to concatenate two strings in C?
a) concat() b) cat() c) stringcat() d) strcat()
5. Which function is used to compare two strings in C?
a) strcmp() b) strcmpi() c) compare() d) cmpi()
6. Which function is used to compare two strings with ignoring case in C?
a) strcmp() b) strcmpi() c) compare() d) cmpi()
7. Which is the correct syntax to declare an array in C?
a) data_type array_name[array_size]; b) data_type array_name{array_size};
c) data_type array_name[]; d) All of the above
8. You can access elements of an array by ___.
a) values b) indices c) memory addresses d) All of the above
9. Which is/are the correct syntax to initialize an array in C?
a) data_type array_name[array_size] = {value1, value2, value3, …};
b) data_type array_name[] = {value1, value2, value3, …};
c) data_type array_name[array_size] = {}; d) Both A and B
10. Array elements are always stored in ___ memory locations.
a) Random b) Sequential c) Both A and B d) None of the above
11. Let x is an integer array with three elements having value 10, 20, and 30. What will be the output
of the following statement? printf("%u",x);
a) Prints the value of 0th element (i.e., 10) b) Prints the garbage value
c) An error occurs d) Print the address of the array (i.e., the address of first (0th) element
12. What will be the output of the following C program?
#include <stdio.h>
int main()
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
{
int x[5] = { 10, 20, 30 };
printf("%ld", sizeof(x)/sizeof(x[0]));
return 0;
}
a) 3 b) 4 c) 5 d) 6
13. What will be the output of the following C program?
#include <stdio.h>
int main()
{
int x[5] = { 10, 20, 30 };
printf("%d", x[3]);
return 0;
}
a) 0 b) 30 c) Garbage value d) Error
14. What will be the output of the following C program?
#include <stdio.h>
int main()
{
int x[5] = { 10, 20, 30 };
printf("%d", x[-1]);
return 0;
}
a) 0 b) 10 c) Garbage value d) Error
15. If we pass an array as an argument to a function, what actually gets passed?
a) Value of elements in array b) First element of the array
c) Base address of the array i.e., the address of the first element
d) Address of the last element of array
OOPS CONCEPTS
1. Wrapping data and its related functionality into a single entity is known as _____________
a) Abstraction b) Encapsulation c) Polymorphism d) Modularity
2. How structures and classes in C++ differ?
a) In Structures, members are public by default whereas, in Classes, they are private by default
b) In Structures, members are private by default whereas, in Classes, they are public by default
c) Structures by default hide every member whereas classes do not
d) Structures cannot have private members whereas classes can have
3. What does polymorphism in OOPs mean?
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
a) Concept of allowing overiding of functions b) Concept of hiding data
c) Concept of keeping things in differnt modules/files
d) Concept of wrapping things into a single unit
4. Which concept allows you to reuse the written code?
a) Encapsulation b) Abstraction c) Inheritance d) Polymorphism
5. Which of the following explains Polymorphism?
a) int func(int, int); float func1(float, float); b) int func(int); int func(int);
c) int func(float); float func(int, int, char); d) int func(); int new_func();
6. Which of the following shows multiple inheritances?
a) A->B->C b) A->B; A->C c) A,B->C d) B->A
7. How access specifiers in Class helps in Abstraction?
a) They does not helps in any way
b) They allows us to show only required things to outer world
c) They help in keeping things together d) Abstraction concept is not used in classes
8. C++ is ______________
a) procedural programming language b) object oriented programming language
c) functional programming language
d) both procedural and object oriented programming language
9. What does modularity mean?
a) Hiding part of program b) Subdividing program into small independent parts
c) Overriding parts of program d) Wrapping things into single unit
10. Which of the following feature of OOPs is not used in the following C++ code?
class A{
int i;
public:
void print() {cout << "hello" << i;}
}
class B : public A{
int j;
public:
void assign (int a ) {k = a;}
}
a) Abstraction b) Encapsulation c) Inheritance d) Polymorphism
11. Which of the following class allows to declare only one object of it?
a) Abstract class b) Virtual class c) Singleton class d) Friend class
12. Which of the following is not a type of Constructor?
a) Friend constructor b) Copy constructor
c) Default constructor d) Parameterized constructor
13. Which of the following is correct?
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
a) Base class pointer object cannot point to a derived class object
b) Derived class pointer object cannot point to a base class object
c) A derived class cannot have pointer objects
d) A base class cannot have pointer objects
14. Out of the following, which is not a member of the class?
a) Static function b) Friend function c) Constant function d) Virtual function
15. What is the other name used for functions inside a class?
a) Member variables b) Member functions c) Class functions d) Class variables
16. Which of the following cannot be a friend?
a) Function b) Class c) Object d) Operator function
17. Why references are different from pointers?
a) A reference cannot be made null b) A reference cannot be changed once initialized
c) No extra operator is needed for dereferencing of a reference d) All of the mentioned
18. Which of the following provides a programmer with the facility of using object of a class inside
other classes? a) Inheritance b) Composition c) Abstraction d) Encapsulation
19. How many types of polymorphism are there in C++?
a) 1 b) 2 c) 3 d) 4
20. How run-time polymorphisms are implemented in C++?
a) Using Inheritance b) Using Virtual functions
c) Using Templates d) Using Inheritance and Virtual functions
21. How compile-time polymorphisms are implemented in C++?
a) Using Inheritance b) Using Virtual functions
c) Using Templates d) Using Inheritance and Virtual functions
22. Which of the following is an abstract data type?
a) int b) float c) class d) string
23. Which concept means the addition of new components to a program as it runs?
a) Data hiding b) Dynamic binding c) Dynamic loading d) Dynamic typing
24. Which of the following explains the overloading of functions?
a) Virtual polymorphism b) Transient polymorphism
c) Ad-hoc polymorphism d) Pseudo polymorphism
25. Which of the following approach is used by C++?
a) Top-down b) Bottom-up c) Left-right d) Right-left
26. Which operator is overloaded for a cout object?
a) >> b) << c) < d) >
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
27. Which of the following cannot be used with the virtual keyword?
a) Class b) Member functions c) Constructors d) Destructors
28. Which concept is used to implement late binding?
a) Virtual functions b) Operator functions
c) Constant functions d) Static functions
29. Which of the following is correct?
a) C++ allows static type checking b) C++ allows dynamic type checking.
c) C++ allows static member function to be of type const.
d) C++ allows both static and dynamic type checking
30. Which of the following supports the concept that reusability is a desirable feature of a language?
a) It reduces the testing time b) It reduces maintenance cost
c) It decreases the compilation time d) It reduced both testing and maintenance time
31. Which of the following is a static polymorphism mechanism?
a) Function overloading b) Operator overloading
c) Templates d) All of the mentioned
32. Which of the following is true?
I) All operators in C++ can be overloaded. II) The basic meaning of an operator can be changed.
a) I only b) II only c) Both I and II d) Neither I nor II
33. Which of the following is not a type of inheritance?
a) Multiple b) Multilevel c) Distributive d) Hierarchical
34. What happens if a class does not have a name?
a) It will not have a constructor b) It will not have a destructor
c) It is not allowed d) It will neither have a constructor or destructor
35. Which of the following statement is true?
I) In Procedural programming languages, all function calls are resolved at compile-time
II) In Object Oriented programming languages, all function calls are resolved at compile-time
a) I only b) II only c) Both I and II d) Neither I nor II
36. Which members are inherited but are not accessible in any case?
a) Private b) Public c) Protected d) Both private and protected
37. Which of the following is correct?
a) Friend functions can access public members of a class
b) Friend functions can access protected members of a class
c) Friend functions can access private members of a class d) All of the mentioned
38. Which of the following is correct in C++?
a) Classes cannot have protected data members b) Structures can have member functions
c) Class members are public by default d) Structure members are private by default
39. Which of the following is used to make an abstract class?
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
a) By using virtual keyword in front of a class declaration
b) By using an abstract keyword in front of a class declaration
c) By declaring a virtual function in a class d) By declaring a pure virtual function in a class
40. Which of the following is correct?
a) A class is an instance of its objects b) An object is an instance of its class
c) A class is an instance of the data type that the class have
d) An object is an instance of the data type of the class
Fundamentals of C++
1. Who created C++?
a) Bjarne Stroustrup b) Dennis Ritchie c) Ken Thompson d) Brian Kernighan
2. C++ Language developed at _________?
a) AT & T's Bell Laboratories of USA in 1972 b) Sun Microsystems in 1973
c) Cambridge University in 1972 d) AT & T's Bell Laboratories of USA in 1979
3. Which one of the following is a keyword?
a) Size b) Key c) Jump d) Switch
4. ____ is the smallest individual unit in a program.
a) Variable b) Control c) Character d) Token
5. Which of the following is the correct syntax of including a user defined header files in C++?
a) #include <userdefined.h> b) #include <userdefined>
c) #include “userdefined” d) #include [userdefined]
6. Which of the following is a correct identifier in C++?
a) 7var_name b) 7VARNAME c) VAR_1234 d) $var_name
7. Which of the following is called address operator?
a) * b) & c) _ d) %
8. C++ is _______ type of programming language.?
a) Object Oriented b) Procedural c) Bit level language d) Functional
9. Which of the following is used for comments in C++?
a) // comment b) /* comment */ c) both // comment or /* comment */ d) // comment */
10. What are the actual parameters in C++?
a) Parameters with which functions are called
b) Parameters which are used in the definition of a function
c) Variables other than passed parameters in a function
d) Variables that are never used in the function
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
11. What are the formal parameters in C++?
a) Parameters with which functions are called
b) Parameters which are used in the definition of the function
c) Variables other than passed parameters in a function
d) Variables that are never used in the function
12. Which function is used to read a single character from the console in C++?
a) cin.get(ch) b) getline(ch) c) read(ch) d) scanf(ch)
13. Which function is used to write a single character to console in C++?
a) cout.put(ch) b) cout.putline(ch) c) write(ch) d) printf(ch)
14. What is a constant that contains a single character enclosed within single quotes?
a) Numeric b) Fixed c) Character d) Floating Point
15. A C++ code line ends with ___
a) A Semicolon (;) b) A Fullstop(.) c) A Comma (,) d) A Slash (/)
16. What are the escape sequences?
a) Set of characters that convey special meaning in a program
b) Set of characters that whose use are avoided in C++ programs
c) Set of characters that are used in the name of the main function of the program
d) Set of characters that are avoided in cout statements
17. Which of the following escape sequence represents carriage return?
a) r b) n c) nr d) c
18. Which of the following escape sequence represents tab?
a) t b) tr c) b d) a
19. Which of the following is called insertion/put to operator?
a) >> b) << c) > d) <
20. Which of the following is called extraction/get from operator?
a) << b) >> c) > d) <
21. A language which has the capability to generate new data types are called ________________
a) Extensible b) Overloaded c) Encapsulated d) Reprehensible
22. Which of the following is not a fundamental type is not present in C but present in C++?
a) int b) float c) bool d) void
23. What is the size of a boolean variable in C++?
a) 1 bit b) 1 byte c) 4 bytes d) 2 bytes
24. Which of the following is C++ equivalent for scanf()?
a) cin b) cout c) print d) input
25. Which of the following is C++ equivalent for printf()?
a) cin b) cout c) print d) input
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
26. Which of the following is an exit-controlled loop?
a) for b) while c) do-while d) all of the mentioned
27. Which of the following is the correct difference between cin and scanf()?
a) both are the same b) cin is a stream object whereas scanf() is a function
c) scanf() is a stream object whereas cin is a function
d) cin is used for printing whereas scanf() is used for reading input
28. Which of the following is an entry-controlled loop?
a) for b) while c) do-while d) both while and for
29.In which part of the for loop termination condition is checked?
for(I;II;III) a) I b) II c) III d) IV
30. Which of the following is the scope resolution operator?
a) . b) * c) :: d) ~
Constants & Data Types
1. The constants are also called as
a) Const b) preprocessor c) literals d) none of these
2. What are the parts of the literal constants?
a) integer numerals b) floating-point numerals
c) strings and boolean values d) all of the mentioned
3. What is the size of wchar_t in C++?
a) 2 b) 4 c) 2 or 4 d) Based on the number of bits in the system
4. Pick the odd one out.
a) array type b) character type c) boolean type d) integer type
5. Which data type is used to represent the absence of parameters?
a) int b) short c) void d) float
6. What does ‘a’ escape code represent?
a) alert b) backslash c) tab d) form feed
7. How the constants are declared?
a) const keyword b) #define preprocessor c) both a and b d) None of these
8. Which type is best suited to represent the logical values?
a) integer b) Boolean c) character d) float
9. Identify the user-defined types from the following?
a) enumeration b) classes c) both enumeration and classes d) int
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
10. Which of the following statements are true?
int f (float)
a) f is a function taking an argument of type int and returning a floating point number
b) f is a function taking an argument of type float and returning an integer
c) f is a function of type float d) f is a function of type int
11. The value 132.54 can be represented using which data type?
a) double b) void c) int d) bool
12. When a language has the capability to produce new data type mean, it can be called as
a) overloaded b) extensible c) encapsulated d) reprehensible
13. Pick the odd one out.
a) integer, character, boolean, floating b) enumeration, classes
c) integer, enum, void d) arrays, pointer, classes
14. How many characters are specified in the ASCII scheme?
a) 64 b) 128 c) 256 d) 24
15. Given the variables p, q are of char type and r, s, t are of int type. Select the right statement?
1. t = (r * s) / (r + s); 2. t = (p * q) / (r + s);
a) 1 is true but 2 is false b) 1 is false and 2 is true
c) both 1 and 2 are true d) both 1 and 2 are false
16. Which of the following belongs to the set of character types?
a) char b) wchar_t c) only a d) both wchar_t and char
17. How do we represent a wide character of the form wchar_t?
a) L’a’ b) l’a’ c) L[a] d) la
18. In C++, what is the sign of character data type by default?
a) Signed b) Unsigned
c) Implementation dependent d) Unsigned Implementation
19. Is the size of character literals different in C and C++?
a) Implementation defined b) Can’t say
c) Yes, they are different d) No, they are not different
20. Suppose in a hypothetical machine, the size of char is 32 bits. What would sizeof(char) return?
a) 4 b) 1 c) Implementation dependent d) Machine dependent
21. What constant defined in <climits> header returns the number of bits in a char?
a) CHAR_SIZE b) SIZE_CHAR c) BIT_CHAR d) CHAR_BIT
22. The size_t integer type in C++ is?
a) Unsigned integer of at least 64 bits b) Signed integer of at least 16 bits
c) Unsigned integer of at least 16 bits d) Signed integer of at least 64 bits
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
23. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int x = -1;
unsigned int y = 2;
if (x > y) {
cout << "x is greater: " ;
}
else
{
cout << "y is greater: " ;
}
return 0;
}
a) x is greater b) y is greater c) implementation defined d) arbitrary
24. Which of these expressions will return true if the input integer v is a power of two?
a) (v | (v + 1)) == 0; b) (~v & (v – 1)) == 0; c) (v | (v – 1)) == 0; d) (v & (v – 1)) == 0;
25. What is the value of the following 8-bit integer after all statements are executed?
1. int x = 1; 2. x = x << 7; 3. x = x >> 7;
a) 1 b) -1 c) 127 d) Implementation defined
26. Which of these expressions will make the rightmost set bit zero in an input integer x?
a) x = x | (x-1) b) x = x & (x-1) c) x = x | (x+1) d) x = x & (x+2)
27. Which of these expressions will isolate the rightmost set bit?
a) x = x & (~x) b) x = x ^ (~x) c) x = x & (-x) d) x = x ^ (-x)
28. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int x = 8;
cout << "ANDing integer 'x' with 'true' : " << x && true;
return 0;
}
a) ANDing integer ‘x’ with ‘true’ :8 b) ANDing integer ‘x’ with ‘true’ :0
c) ANDing integer ‘x’ with ‘true’ :1 d) ANDing integer ‘x’ with ‘true’ :9
29. 0946, 786427373824, ‘x’ and 0X2f are _____ _____ ____ and _____ literals respectively.
a) decimal, character, octal, hexadecimal b) octal, hexadecimal, character, decimal
c) hexadecimal, octal, decimal, character d) octal, decimal, character, hexadecimal
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
30. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int i = 3;
int l = i / -2;
int k = i % -2;
cout << l << k ;
return 0;
}
a) compile time error b) -1 1 c) 1 -1 d) implementation defined
Decision making & Loops
1. How many sequences of statements present in C++?
a) 4 b) 3 c) 5 d) 6
2. Decision Control statements in C++ can be implemented using
a) if b) if-else c) Conditional Operator d) All of the above
3. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
if (0) {
cout << "Hello" ;
}
else
{
cout << "Good Bye" ;
}
return 0;
}
a) Hello b) Good Bye c) HelloGood bye d) Compilation Error
4. if you have to make decision based on multiple choices, which of the following is best suited?
a) if b) if-else c) if-else-if d) All of the above
5. Can we use string inside switch statement?
a) Yes b) No
6. In situations where we need to execute body of the loop before testing the condition, we should
use_____. a) For loop b) while loop c) do-while loop d) nested for loop
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
7. Loops in C++ Language are implemented using?
a) While loop b) For loop c) Do while loop d) All of the above
8. While loop is faster in C++ Language, for, while or do-while?
a) For b) while c) do-while d) All work ate same speed
9. What is the way to suddenly come out of or quit any loop in C++?
a) continue; statement b) break; statement
c) leave; statement d) quit; statement
10. Which of the following can replace a simple if -wlsw construct?
a) Ternary operator b) while loop c) do-while loop d) fop loop
11. The if...else statement can be replaced by which operator?
a) Bitwise operator b) Conditional operator
c) Multiplicative operator d) Addition operator
12. The switch statement is also called as?
a) choosing structure b) selective structure
c) certain structure d) bitwise structure
13. Choose a correct C++ for loop syntax.
a) for(initalization; condition; inc/dec){ // statements };
b) for(declaration; condition; incrementoperation){ // statements };
c) for(declaration; incrementoperation; condition){ // statements };
d) for(initalization; condition; incrementoperation){ // statements };
14. Choose a correct C++ do while syntax.
a) dowhile(condition){ // statements }; b) do while(condition){ // statements };
c) do{ // statements }while(condition) d) do{ // statements }while(condition);
15. Choose a correct C++ Statement.
a) a++ is (a= a+1) POST INCREMENT operator
b) a-- is (a = a-1) POST DECREMENT operator. --a is (a = a-1) PRE DECREMENT operator
c) ++a is (a = a+1) PRE INCREMENT operator d) All of the above.
16. Which of the following is an entry-controlled loop?
a) For loop b) while loop c) do-while loop d) both b & c
17. Which of the following is an exit-controlled loop?
a) While loop b) For loop c) Do while loop d) both b & c
18. Which of the following is most suitable for a menu-dricen program?
a) For b) while c) do-while d) All of the above
19. Consider the following loop: for(int i = 0; i<5; i++);
a) It will give compilation error. b) 5 c) 6 d) Some Garbage value
20. A switch construct can be used with which of the following types of variable?
a) int b) int, char c) int, float, char d) Any basic datatype
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
21. The destination statement for the goto label is identified by what label?
a) $ b) @ c) * d) :
22. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int n ;
for (n = 5; n < 0; n--)
{
cout << n;
if (n == 3)
break;
}
return 0;
}
a) 543 b) 54 c) 5432 d) 53
23. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a = 10;
if (a = 15)
{
time;
cout << a;
if (n == 3)
goto time;
}
break;
return 0;
}
a) 1010 b) 10 c) infinitely print 10 d) compile time error
24. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int n = 15;
for (; ;)
cout << n;
return 0;
}
a) error b) 15 c) infinite times of printing n d) none of the mentioned
25. Which looping process is best used when the number of iterations is known?
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
a) While loop b) For loop c) Do while loop
d) all looping processes require that the iterations be known
26. How many types of loops are there in C++?
a) 4 b) 2 c) 3 d) 1
27. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int i ;
for (i = 0; i < 10; i++);
{
cout << i;
}
return 0;
}
a) 0123456789 b) 10 c) 012345678910 d) compile time error
28. Which of the following must be present in switch construct?
a) Expression in ( ) after switch b) default
c) case followed by value d) All of the above
29. What is the effect of writing a break statement inside a loop?
a) It cancels remaining iterations. b) It skips a particular iteration.
c) The program terminates immediately. d) Loop counter is reset.
30. The break statement causes an exit
a) fromthe innermost loop only. b) only from the innermost switch.
c) from all loops & switches. d) from the innermost loop or switch.
Operators
1. Which operator is having the right to left associativity in the following?
a) Array subscripting b) Function call c) Addition and subtraction d) Type cast
2. What are the essential operators in c++?
a) + b) | c) <= d) All of the mentioned
3. In which direction does the assignment operation will take place?
a) left to right b) right to left c) top to bottom d) bottom to top
4. Pick out the compound assignment statement.
a) a = a – 5 b) a = a / b c) a -= 5 d) a = a + 5
5. What is the associativity of add(+); ?
a) right to left b) left to right c) right to left & left to right d) top to bottom
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
6. What is the name of | operator?
a) sizeof b) or c) and d) modulus
7. Which operator is having the highest precedence in c++?
a) array subscript b) Scope resolution operator c) static_cast d) dynamic_cast
8. Which operator is having the highest precedence?
a) postfix b) unary c) shift d) equality
9. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a, b;
a = 10;
b = 4;
a = b;
b = 7;
cout << "a: " << a;
cout << "nb: " << b;
return 0;
}
a) a:4 b:7 b) a:10 b:4 c) a:4 b:10 d) a:4 b:6
10. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a, b, c;
a = 2;
b = 7;
c = (a > b) ? a : b;
cout << "c: " << c;
return 0;
}
a) 2 b) 7 c) 9 d) 14
11. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a;
a = 5 + 3 * 5;
cout << "a: " << a;
return 0;
}
a) 35 b) 20 c) 25 d) 30
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
12. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a = 0;
int b = 10;
a = 2;
b = 7;
if (a && b) {
cout << "true: " << endl;
}
else
{
cout << "false: " << endl;
}
return 0;
}
a) true b) false c) error d) 10
13. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a = 5, b = 6, c, d;
c = a, b;
d = (a ,b);
cout << c << " " << d;
return 0;
}
6 a) 5 5 b) 6 7 c) 6 8 d) 6
14. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int i, j;
j = 10;
i = (j++, j + 100, 999 + j);
cout << i;
return 0;
}
a) 1000 b) 11 c) 1010 d) 1001
15. What is the use of dynamic_cast operator?
a) it converts virtual base class to derived class
b) it converts the virtual base object to derived objects
c) it will convert the operator based on precedence
d) it converts the virtual base object to derived class
16. What will be the output of the following C++ code?
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
#include <iostream>
using namespace std;
int main() {
int x, y;
x = 5;
y = ++x * ++x;
cout << x << y;
y = x++ * ++x;
cout << x << y;
return 0;
}
a) 749735 b) 736749 c) 367497 d) 367597
18. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a = 5, b = 6, c;
c = (a > b) ? a : b;
cout << c;
return 0;
}
a) 6 b) 5 c) 4 d) 7
19. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
double a = 21.09399;
float b = 10.20;
int c, d;
c = (int) a;
d = (int) b;
cout << c << " " << d;
return 0;
}
10 a) 20 21 b) 10 10 c) 21 20 d) 10
20. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a = 20, b = 10, c = 15, d = 5;
int e;
e = a + b * c / d;
cout << e << endl;
return 0;
}
a) 50 b) 60 c) 70 d) 90
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
21. What is this operator called "?:" ?
a) condtional b) relational c) casting operator d) unrelational
C++ Functions
1. Where does the execution of the program starts?
a) user-defined function b) main function
c) void function d) else function
2. What are mandatory parts in the function declaration?
a) return type, function name b) return type, function name, parameters
c) parameters, function name d) parameters, variables
3. which of the following is used to terminate the function declaration?
a) : b) ) c) ; d) ]
4. How many can max number of arguments present in function in the c99 compiler?
a) 99 b) 90 c) 102 d) 127
5. Which is more effective while calling the functions?
a) call by value b) call by reference c) call by pointer d) call by object
6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void car{
cout << "Audi R8";
}
int main() {
car();
return 0;
}
a) Audi R8 b) Audi R8Audi R8 c) compile time error d) runtime error
7. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void fun(int x, int y){
x = 20;
y = 10;
}
int main() {
int x = 10;
fun (x, x);
cout << x;
return 0;
}
a) 10 b) 20 c) compile time error d) 30
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
8. What happens to a function defined inside a class without any complex operations (like looping, a
large number of lines, etc)?
a) It becomes a virtual function of the class b) It becomes a default calling function of the class
c) It becomes an inline function of the class d) The program gives an error
9. What is the scope of the variable declared in the user defined function?
a) whole program b) only inside the {} block c) the main function d) header section
10. How many minimum number of functions should be present in a C++ program for its execution?
a) 0 b) 1 c) 2 d) 3
11. Which of the following is the default return value of functions in C++?
a) int b) char c) float d) void
12. What is an inline function?
a) A function that is expanded at each call during execution
b) A function that is called during compile time
c) A function that is not checked for syntax errors
d) A function that is not checked for semantic analysis
13. In which of the following cases inline functions may not word?
i) If the function has static variables. ii) If the function has global and register variables.
iii) If the function contains loops iv) If the function is recursive
a) i, iv b) iii, iv c) ii, iii, iv d) i, iii, iv
14. When we define the default values for a function?
a) When a function is defined b) When a function is declared
c) When the scope of the function is over d) When a function is called
15. Where should default parameters appear in a function prototype?
a) To the rightmost side of the parameter list b) To the leftmost side of the parameter list
c) Anywhere inside the parameter list d) Middle of the parameter list
16. If an argument from the parameter list of a function is defined constant then _______________
a) It can be modified inside the function b) It cannot be modified inside the function
c) Error occurs d) Segmentation fault
17. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int fun(int x = 0, int y = 0, int z){
return (x + y + z);
}
int main() {
cout << fun(10);
return 0;
}
a) 10 b) 0 c) Error d) Segmentation fault
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
18. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int fun(int = 0, int = 0);
int main() {
cout << fun(5);
return 0;
}
int fun(int x, int y){
return (x + y);
}
a) -5 b) 0 c) 10 d) 5
19. Which of the following feature is used in function overloading and function with default
argument? a) Encapsulation b) Polymorphism c) Abstraction d) Modularity
20. An inline function is expanded during ______________
a) compile-time b) run-time c) never expanded d) end of the program
C++ Arrays & Strings
1. Which of the following correctly declares an array?
a) int array[10]; b) int array; c) array{10}; d) array array[10];
2. What is the index number of the last element of an array with 9 elements?
a) 9 b) 8 c) 0 d) Programmer-defined
3. What is the correct definition of an array?
a) An array is a series of elements of the same type in contiguous memory locations
b) An array is a series of element
c) An array is a series of elements of the same type placed in non-contiguous memory locations
d) An array is an element of the different type
4. Which of the following gives the memory address of the first element in array?
a) array[0]; b) array[1]; c) array(2); d) array;
5. Which of the following accesses the seventh element stored in array?
a) array[6]; b) array[7]; c) array(7); d) array;
6. What is the difference between unsigned int length() and unsigned int size()?
a) Returns a different value b) They are same
c) Returns a different value but they are same d) Returns a length
7. Which header file is used to manipulate the string?
a) iostream b) iomanip c) string d) container
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
8. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main() {
for (temp = 0; temp < 5; temp++){
result += array1[temp];
}
for (temp = 0; temp < 4; temp++){
result += array2[temp];
}
cout << result;
return 0;
}
a) 6553 b) 6533 c) 6522 d) 12200
9. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 8; n++){
result += array[n];
}
cout << result;
return 0;
}
a) 25 b) 26 c) 27 d) 21
10. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a = 5, b = 10, c = 15;
int arr[3] = {&a, &b, &c};
cout << *arr[*arr[1] - 0];
return 0;
}
a) 15 b) 18 c) garbage value d) compile time error
11. How many maximum number of parameters does a string constructor can take?
a) 1 b) 2 c) 3 d) 4
12. Which constant member functions does not modify the string?
a) bool empty() b) assign c) append d) delete
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
13. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
char str[5] = "ABC";
cout << str [3];
cout << str;
return 0;
}
a) ABC b) ABCD c) AB d) AC
14. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
char array[] = [10, 20, 30];
cout << -2 [array];
return 0;
}
a) -15 b) -30 c) compile time error d) garbage value
15. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() {
string str {"Steve jobs"};
cout << str.capacity() << "n";
return 0;
}
a) 9 b) 10 c) 11 d) Not Fix
16. Wht will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() {
string str {"Steve jobs founded the apple"};
string str {"apple"};
unsigned found = str.find(str2);
if (found != string :: npos)
cout << found << "n";
return 0;
}
a) apple b) 12 c) 23 d) Steve jobs founded the
17. How many parameters can a resize method take?
a) 1 b) 2 c) 1 or 2 d) 2
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
18. What will be the output of the following C++ code?
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main() {
string str {"Steve jobs"};
char * cstr = new char [str.length() + 1];
strcpy (cstr, str.c_str());
char * p = strtok (cstr, " ");
while (p != 0)
{
cout << p << "n";
p = strtok(NULL, " ");
}
delete[] cstr;
return 0;
}
a) Steve jo b) Steve jobs c) Steve jobs d) Steve jo
19. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() {
string str {"Steve jobs"};
unsigned long int found = str.find_first_of("aeiou");
while (found != string :: npos)
{
str[found] = '*';
found = str.find_first_of("aeiou", found + 1);
}
cout << str << "n";
return 0;
}
a) Steve b) jobs c) St*v* j*bs d) St*v*
20. Which of the following is correct about remove_extent() function?
a) Removes the given dimension from an array
b) Removes the first dimension from the right of the array
c) Removes the first dimension from the left of the array
d) Removes the last dimension from the left of the array
21. What is the use of is_array() function in C++?
a) To check if a variable is array type or not b) To check if a variable is 1-D array type or not
c) To check if a variable is 2-D array type or not
d) To check if a variable is 1-D or 2-D array type or not
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
22. Which of the header file is used for array type manipulation?
a) <array> b) <type_traits> c) <iostream> d) std namespace
23. What is the use of is_same() function in C++?
a) To check if a variable is array type or not
b) To check whether two variables have the same characteristics
c) To check if two variable is of array type or not
d) To check whether two variables are different or not
24. Which of the following is correct about extent() function?
a) Returns how many elements are in array currently
b) Returns the size of the 1st dimension
c) Returns how many total elements can be stored in an array
d) Returns the size of a given dimension
25. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << is_same <int, char> :: value;
cout << is_same <char [10], char [10]> :: value;
cout << is_same <char * [10], string]> :: value;
return 0;
}
a) 011 b) 101 c) 010 d) 110
26. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << rank <int [10]> :: value;
cout << rank <char [10] [10]> :: value;
cout << rank < string [10] [10] [10]> :: value;
return 0;
}
a) 111 b) 123 c) 321 d) 121
27. What is the use of rank() function in C++?
a) Returns size of each dimension b) Returns how many total elements can be stored in an array
c) Returns how many elements are in array currently d) Returns the dimension of an array
28. Which of the following is correct about remove_all_extents() function?
a) Removes the all dimension from an array
b) Removes the first dimension from the left of the array
c) Removes the first dimension from the right of the array
d) Removes the last dimension from the left of the array
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
29. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << is_array <int> :: value;
cout << is_array <char [10]> :: value;
cout << is_array <string]> :: value;
return 0;
}
a) 010 b) 101 c) 001 d) 110
30. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << extent < string [10][20][30], 0> :: value;
cout << extent < string [10][20][30], 1> :: value;
cout << extent < string [10][20][30], 2> :: value;
return 0;
}
a) 101010 b) 102030 c) 302010 d) 102010
Structures
1. What will happen when the structure is declared?
a) it will not allocate any memory b) it will allocate the memory
c) it will be declared and initialized d) it will be declared
2. What will be the output of the following C++ code?
#include <iostream>
#include <string.h>
using namespace std;
int main() {
int student{
int num;
char name[25];
}
student stu;
stu.num = 123;
strcpy(stu.num, "john");
cout << stu.num << endl;
cout << stu.name << endl;
return 0;
}
a) 123 john b) john john c) compile time error d) runtime error
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
3. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
struct Time{
int hours, minutes, seconds;
}
int toSeconds(Time now);
int main() {
Time t;
t.hours = 5;
t.minutes = 30;
t.seconds = 45;
cout << "Total seconds: " << toSeconds(t) << endl;
return 0;
}
int toSeconds (Time now){
return 3600 * now.hours + 60 * now.minutes + now.seconds;
}
a) 19845 b) 20000 c) 15000 d) 19844
4. The data elements in the structure are also known as what?
a) objects b) members c) data d) objects & data
5. What will be used when terminating a structure?
a) : b) } c) ; d) ;;
6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
struct ShoeType{
string style;
double price;
};
ShoeType shoe1, shoe2;
shoe1.style = "Adidas";
shoe1.price = 9.99;
cout << shoe1.style << "$" << shoe1.price;
shoe2 = shoe1;
shoe2.price = shoe2.price / 9;
cout << shoe2.style << "$" << shoe2.price;
return 0;
}
a) Adidas $ 9.99Adidas $ 1.11 b) Adidas $ 9.99Adidas $ 9.11
c) Adidas $ 9.99Adidas $ 11.11 d) Adidas $ 11.11Adidas $ 11.11
7. The declaration of the structure is also called as?
a) structure creator b) structure signifier
c) structure specifier d) structure creator & signifier
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
8. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
struct sec{
int a;
char b;
};
int toSeconds(Time now);
int main() {
struct sec s = {25, 50};
struct sec *ps = (struct sec *) &s;
cout << ps-> a << ps-> b ;
return 0;
}
a) 252 b) 253 c) 254 d) 262
9. Which of the following is a properly defined structure?
a) struct {int a;} b) struct a_struct {int a;}
c) struct a_struct int a; d) struct a_struct {int a;};
10. Which of the following accesses a variable in structure *b?
a) b->var; b) b.var; c) b-var; d) b>var;
C++ Pointers
1. What does the following statement mean?
int (*fp) (char*);
a) pointer to a pointer b) pointer to an array of chars
c) pointer to function taking a char* argument and returns an int
d) function taking a char* argument and returning a pointer to int
2. The operator used for dereferencing or indirection is ____
a) * b) & c) -> d) –>>
3. Choose the right option. string* x, y;
a) x is a pointer to a string, y is a string b) y is a pointer to a string, x is a string
c) both x and y are pointers to string types d) y is a pointer to a string
4. Which one of the following is not a possible state for a pointer.
a) hold the address of the specific object b) point one past the end of an object
c) zero d) point to a type
5. Which of the following is illegal?
a) int *ip; b) string s, *sp = 0; c) int i; double* dp = &i; d) int *pi = 0;
6. 8. The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char
and returns a pointer to a pointer to a integer is ____________
a) int **fun(float**, char**) b) int *fun(float*, char*)
c) int **fun(float*, char**) d) int ***fun(*float, **char)
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
7. What will happen in the following C++ code snippet?
int a =100, b =200;
int *p = &a, *q = &b ;
p = q
a) b is assigned to a b) p now points to b c) a is assigned to b d) q now points to a
8. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a = 5, b = 10, c = 15;
int *arr[] = {&a, &b, &c};
cout << arr[1];
return 0;
}
a) 5 b) 10 c) 15 d) it will return some random number
9. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
char arr[20];
int i;
for (i = 0; i < 10; i++)
*(arr + i) = 65 + i;
*(arr + i) = '0';
cout << arr;
return 0;
}
a) ABCDEFGHIJ b) AAAAAAAAAA c) JJJJJJJJ d) AAAAAAJJJJ
10. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
char *ptr;
char str[] = 'abcdefg';
ptr = str;
ptr += 5;
cout << ptr;
return 0;
}
a) fg b) cdef c) defg d) abcd
11. What is the meaning of the following declaration?
int (*p [5]) ();
a) p is pointer to function b) p is array of pointer to function
c) p is pointer to such function which return type is the array d) p is pointer to array of function
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
12. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};
cout << *(a[1] + 2) << * (*(a + 1) + 2) << [1[a]];
return 0;
}
a) 15 18 21 b) 21 21 21 c) 24 24 24 d) Compile time error
13. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int arr[] = {4, 5, 6, 7};
int *p = (arr + 1);
cout << *p;
return 0;
}
a) 4 b) 5 c) 6 d) 7
14. What will happen in the following C++ code snippet?
#include <iostream>
using namespace std;
int main() {
int arr[] = {4, 5, 6, 7};
int *p = (arr + 1);
cout << arr;
return 0;
}
a) 4 b) 5 c) address of arr d) 7
15. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int numbers[5];
int *p;
p = numbers; *p = 10;
p++; *p = 20;
p = numbers[2]; *p = 30;
p = numbers + 3; *p = 40;
p = numbers; *(p + 4) = 50;
for (int n = 0; n < 5; n++){
cout << numbers[n] << ",";
}
return 0;
}
a) 10,20,30,40,50, b) 1020304050 c) compile error d) runtime error
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
16. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int arr[] = {4, 5, 6, 7};
int *p = (arr + 1);
cout << *arr + 9;
return 0;
}
a) 12 b) 5 c) 13 d) error
17. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int i;
const char *arr[] = {"c", "c++", "java", "VBA"};
const char *(*ptr)[4] = &arr;
cout << ++(*ptr)[2];
return 0;
}
a) ava b) java c) c++ d) compile time error
18. The void pointer can point to which type of objects?
a) int b) float c) double d) all of the mentioned
19. When does the void pointer can be dereferenced?
a) when it doesn’t point to any value b) when it cast to another type of object
c) using delete keyword d) using shift keyword
20. What is size of generic pointer in C++ (in 32-bit platform)?
a) 2 b) 4 c) 8 d) 0
C++ File Management
1. Which header file is required to use file I/O operations?
a) <ifstream> b) <ostream> c) <fstream> d) <iostream>
2. Which stream class is to only write on files?
a) ofstream b) ifstream c) iostream d) fstream
3. Which of the following is used to create an output stream?
a) ofstream b) ifstream c) iostream d) fstream
4. Which of the following is used to create a stream that performs both input and output operations?
a) ofstream b) ifstream c) iostream d) fstream
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
5. Which of the following is not used as a file opening mode?
a) ios::trunk b) ios::binary c) ios::in d) ios::ate
6. Which of the following statements are correct?
1) It is not possible to combine two or more file opening mode in open() method.
2) It is possible to combine two or more file opening mode in open() method.
3) ios::in and ios::out are input and output file opening mode respectively.
a) 1, 3 b) 2, 3 c) 3 only d) 1, 2
7. By default, all the files in C++ are opened in _________ mode.
a) Text b) Binary c) ISCII d) VTC
8. What is the use of ios::trunc mode?
a) To open a file in input mode b) To open a file in output mode
c) To truncate an existing file to half d) To truncate an existing file to zero
9. Which of the following is the default mode of the opening using the ofstream class?
a) ios::in b) ios::out c) ios::app d) ios::trunc
10. What is the return type open() method?
a) int b) char c) bool d) float
11. Which of the following is not used to seek file pointer?
a) ios::set b) ios::end c) ios::cur d) ios::beg
12. Which of the following is the default mode of the opening using the ifstream class?
a) ios::in b) ios::out c) ios::app d) ios::trunc
13. Which of the following is the default mode of the opening using the fstream class?
a) ios::in b) ios::out c) ios::in|ios::out d) ios::trunc
14. Which function is used in C++ to get the current position of file pointer in a file?
a) tell_p() b) get_pos() c) get_p() d) tell_pos()
15. Which function is used to reposition the file pointer?
a) moveg() b) seekg() c) changep() d) go_p()
16. Which of the following is used to move the file pointer to start of a file?
a) ios::beg b) ios::start c) ios::cur d) ios::first
17. It is not possible to combine two or more file opening mode in open () method.
a) True b) False c) May be d) None of these
18. Which of these is the correct statement about eof() ?
a) Returns true if a file open for reading has reached the next character.
b) Returns true if a file open for reading has reached the next word.
c) Returns true if a file open for reading has reached the end.
d) Returns true if a file open for reading has reached the middle.
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
19. Which of the following true about FILE *fp
a) FILE is a structure and fp is a pointer to the structure of FILE type
b) FILE is a buffered stream c) FILE is a stream
d) FILE is a keyword in C for representing files and fp is a variable of FILE type
20. Which of the following methods can be used to open a file in file handling?
a) Using Open ( ) b) Constructor method c) Destructor method d) Both A and B
21. Which operator is used to insert the data into file?
a) >> b) << c) < d) None of the above
22. Which is correct syntax?
a) myfile:open ("example.bin", ios::out); b) myfile.open ("example.bin", ios::out);
c) myfile::open ("example.bin", ios::out); d) myfile.open ("example.bin", ios:out);
23. In fopen(), the open mode "wx" is sometimes preferred "w" because. i) Use of wx is more
efficient. ii) If w is used, old contents of file are erased and a new empty file is created. When wx is
used, fopen() returns NULL if file already exists.
a) Only I b) Only ii c) Both i & ii d) None of the above
24. ios::trunc is used for ?
a) If the file is opened for output operations and it already existed, no action is taken.
b) If the file is opened for output operations and it already existed, then a new copy is created.
c) None of the above
d) If the file is opened for output operations and it already existed, its previous content is deleted
and replaced by the new one.
25. What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main() {
char fine, course;
cout << "Enter a word: ";
fine = cin.get();
cin.sync();
course = cin.get();
cout << fine << endl;
cout << course << endl;
return 0;
}
a) course b) fine c) None of the mentioned
d) Returns fine 2 letter or number from the entered word
26. Which of the following is not a file opening mode ____ .
a) ios::ate b) ios::nocreate c) ios::noreplace d) ios::truncate
27. Due to ios::trunc mode, the file is truncated to zero length.
a) True b) False
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word
28. Which member function is used to determine whether the stream object is currently associated
with a file? a) is_open b) Buf c) String d) None of the above
29. getc() returns EOF when
a) End of files is reached b) When getc() fails to read a character
c) Both A & B d) None of the above
30. If we have object from fstream class, then what is the default mode of opening the file?
a) ios::in|ios::out b) ios::in|ios::out|ios::trunk
c) ios::in|ios::trunk d) Default mode depends on compiler

More Related Content

PDF
C Language MCQ Programming Theory Questions
PDF
CSS MCQ (Cascading Style Sheet Question)
PDF
JavaScript MCQ (JS Coding Questions and Answers)
PDF
C programming notes
PDF
COPA Question Bank MS Excel MCQ with Answers
PDF
Data structure - mcqs
PDF
ITI COPA MySQL MCQ Database Concept (DBMS)
RTF
C Language MCQ Programming Theory Questions
CSS MCQ (Cascading Style Sheet Question)
JavaScript MCQ (JS Coding Questions and Answers)
C programming notes
COPA Question Bank MS Excel MCQ with Answers
Data structure - mcqs
ITI COPA MySQL MCQ Database Concept (DBMS)

What's hot (20)

PDF
Top C Language Interview Questions and Answer
DOCX
C++ 260 MCQ Question with Answer for all Units
PPTX
C programming Training in Ambala ! Batra Computer Centre
PDF
Internet MCQ (Web Technology Questions and Answers)
PDF
Email MCQ (Computer E-Mail Related Question)
PDF
Chapter 2 : Balagurusamy_ Programming ANsI in C
PDF
200 mcq c++(Ankit dubey)
PDF
COPA Practice Set (Previous Year Question Paper)
PDF
Html interview-questions-and-answers
PDF
Bharat Skills COPA Question Bank with Answers
PPT
Friends function and_classes
PDF
COPA MS Word MCQ Important Question in Hindi
PPS
Clanguage
PDF
ITI Employability Skills Questions and Answers
PDF
MS Access MCQ Questions in Hindi Microsoft Office
PDF
COPA CTI Entrance Exam Question (CITS Questions)
PDF
ITI Employability Skills Book PDF MCQ in Hindi
PDF
COPA Trade PPT PowerPoint Most Important MCQ
PPT
Cascading Style Sheet
Top C Language Interview Questions and Answer
C++ 260 MCQ Question with Answer for all Units
C programming Training in Ambala ! Batra Computer Centre
Internet MCQ (Web Technology Questions and Answers)
Email MCQ (Computer E-Mail Related Question)
Chapter 2 : Balagurusamy_ Programming ANsI in C
200 mcq c++(Ankit dubey)
COPA Practice Set (Previous Year Question Paper)
Html interview-questions-and-answers
Bharat Skills COPA Question Bank with Answers
Friends function and_classes
COPA MS Word MCQ Important Question in Hindi
Clanguage
ITI Employability Skills Questions and Answers
MS Access MCQ Questions in Hindi Microsoft Office
COPA CTI Entrance Exam Question (CITS Questions)
ITI Employability Skills Book PDF MCQ in Hindi
COPA Trade PPT PowerPoint Most Important MCQ
Cascading Style Sheet
Ad

Similar to C & C++ 1 WORD MCQ with ANSWER - AI & DS.pdf (20)

PDF
Computer programming mcqs
DOCX
Computer programming questions
DOCX
Computer programming questions
PDF
PDF
this pdf very much useful for embedded c programming students
DOCX
C question bank
DOCX
(Www.entrance exam.net)-tcs placement sample paper 2
PDF
PDF
Reduce course notes class xii
PDF
C aptitude 1st jan 2012
PDF
important C questions and_answers praveensomesh
PDF
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
PDF
Unit 1
PDF
Test Bank for C How to Program 7th Edition by Deitel ISBN 9789332555310 97801...
PDF
Test Bank for C How to Program 7th Edition by Deitel ISBN 9789332555310 97801...
PPTX
Std 10 Chapter 10 Introduction to C Language Important MCQs
PDF
Technical_Interview_Questions.pdf
PDF
Model question paper_mc0061
PDF
C interview questions
PDF
C certification-questions
Computer programming mcqs
Computer programming questions
Computer programming questions
this pdf very much useful for embedded c programming students
C question bank
(Www.entrance exam.net)-tcs placement sample paper 2
Reduce course notes class xii
C aptitude 1st jan 2012
important C questions and_answers praveensomesh
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
Unit 1
Test Bank for C How to Program 7th Edition by Deitel ISBN 9789332555310 97801...
Test Bank for C How to Program 7th Edition by Deitel ISBN 9789332555310 97801...
Std 10 Chapter 10 Introduction to C Language Important MCQs
Technical_Interview_Questions.pdf
Model question paper_mc0061
C interview questions
C certification-questions
Ad

More from ANUSUYA S (14)

DOCX
PYHTON MCQ with ANSWER - AI & DS.docx PYHTON MCQ with ANSWER according to Bha...
PDF
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
DOCX
DBMS 1 WORD MCQ with ANSWER - I M.Com CA.docx
PDF
Internet QP.pdfI CS AI & DS Internet Programming SEMESTER Novv2023.PDF
PDF
OSD uni QP dec 2023.pdfI CS AI & DS OS Design SEMESTER Nov 2023.PDF
PDF
Database Management System previous year question paper M.Com CA QP
PDF
Digital Old Question Paper for Reference (Bharathiyar University)
PDF
C Old Question Paper for Reference (Bharathiyar University)
PDF
C++ Old Question Paper for Reference (Bharathiyar University)
PPTX
C++ - UNIT_-_V.pptx which contains details about File Concepts
PPTX
C++ - UNIT_-_II.pptx which used to contain breif description about classes & ...
PPTX
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
PPTX
C++ - UNIT_-_III.pptx which contains detail description of Operator & Overloa...
PPTX
C++ - UNIT_-_IV.pptx which contains details about Pointers
PYHTON MCQ with ANSWER - AI & DS.docx PYHTON MCQ with ANSWER according to Bha...
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
DBMS 1 WORD MCQ with ANSWER - I M.Com CA.docx
Internet QP.pdfI CS AI & DS Internet Programming SEMESTER Novv2023.PDF
OSD uni QP dec 2023.pdfI CS AI & DS OS Design SEMESTER Nov 2023.PDF
Database Management System previous year question paper M.Com CA QP
Digital Old Question Paper for Reference (Bharathiyar University)
C Old Question Paper for Reference (Bharathiyar University)
C++ Old Question Paper for Reference (Bharathiyar University)
C++ - UNIT_-_V.pptx which contains details about File Concepts
C++ - UNIT_-_II.pptx which used to contain breif description about classes & ...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ - UNIT_-_III.pptx which contains detail description of Operator & Overloa...
C++ - UNIT_-_IV.pptx which contains details about Pointers

Recently uploaded (20)

PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
International_Financial_Reporting_Standa.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
Journal of Dental Science - UDMY (2021).pdf
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PPTX
Education and Perspectives of Education.pptx
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
PDF
semiconductor packaging in vlsi design fab
PDF
advance database management system book.pdf
PPTX
Module on health assessment of CHN. pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
AI-driven educational solutions for real-life interventions in the Philippine...
International_Financial_Reporting_Standa.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
Journal of Dental Science - UDMY (2021).pdf
Uderstanding digital marketing and marketing stratergie for engaging the digi...
Education and Perspectives of Education.pptx
What if we spent less time fighting change, and more time building what’s rig...
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
semiconductor packaging in vlsi design fab
advance database management system book.pdf
Module on health assessment of CHN. pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
Core Concepts of Personalized Learning and Virtual Learning Environments
Cambridge-Practice-Tests-for-IELTS-12.docx

C & C++ 1 WORD MCQ with ANSWER - AI & DS.pdf

  • 1. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word SRI VASAVI COLLEGE, SFW, ERODE 340 C & C++ MCQ with ANSWERS C Introduction (20), C Data Types, Operators and Expressions(25), Conditional Statements & Looping(30), Arrays & Strings(15) ,Oops (40), C++ Fundamentals(30), Constants & Data types(30), Decision Making & Looping(30), Operators(20), Functions(20), Arrays Strings(30), Structures(10) & Pointer(20), File(30) Prepare by Drs. S.ANUSUYA, MCA., M.Phil.,Ph.D., ASSISTANT PROFESSOR & HEAD in COMPUER SCIENCE (AI & DS) Sri Vasavi College (SFW), Erode anuciaa@gmail.com C INTRODUCTION 1. Who is the father of C language? a) Steve Jobs b) James Gosling c) Dennis Ritchie d) Rasmus Lerdorf 2. In which year was C language developed? a) 1962 b) 1978 c) 1979 d) 1972 3. All keywords in C are in ____________ a) LowerCase letters b) UpperCase letters c) CamelCase letters d) None 4. C language is a successor to which language? a) Basic b) Cobol c) C++ d) B 4. C is a ___. a) Low level language b) High level language c) Medium level language d) None above 5. How many keywords are there in C language? a) 32 b)33 c)64 d) 18 6. C language is a ___. a) Procedural oriented programming language b) General purpose programming language c) Structured programming d) All of the above 7. Which is not a valid keyword in C language? a) for b) while c) do-while d) switch
  • 2. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 8. What is an identifier in C language? a) An identifier is a combination of alphanumeric characters used for conditional and control statements b) An identifier is a combination of alphanumeric characters used for any variable, function, label name c) Both A and B d) None of the above 9. A C-style comment, simply surround the text with ___. a) /* and */ b) // and // c) // d) /** and **/ 10. Can we place comments between the statement to comments a part of the code? a) Yes b) No 11. ___ is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard? a) C b) C++ c) C89 d) C99 12. In which version of C language, the C++ Style comment (//) are introduced? a) C17 b) C18 c) C89 d) C99 13. The C source file is processed by the ___. a) Interpreter b) Compiler c) Both Interpreter and Compiler d) Assembler 14. How many whitespace characters are allowed in C language? a) 2 b) 3 c) 4 d) 5 15. How many punctuation characters are allowed in C language? a) 29 b) 30 c) 31 d) 32 16. What is the extension of a C language source file? a) .c b) .cpp c) .c99 d) .h 17. What is the extension of a C language header file? a) .c b) .cpp c) .c99 d) .h 18. To develop which operating, C language was invented? a) Linux b) Unix c) Android d) Mac 19. Does C language support object-oriented approach? a) Yes b) No 20. Which is/are the disadvantage(s) of C language? a) No Garbage Collection b) Inefficient Memory Management c) Low level of abstraction d) Lack of Object Orientation e) All of the above
  • 3. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word C DATA TYPES, OPERATORS AND EXPRESSIONS 1. Which are the fundamental data types in C? a) char b) int c) float d) All of the above 2. How many byte(s) does a char type take in C? a) 1 b) 2 c) 3 d) 4 3. For which type, the format specifier "%i" is used? a) int b) char c) float d) double 4. What is the difference between float and double in C? a) both are used for the same purpose b) double can store just double value as compare to float value c) double is an enhanced version of float and was introduced in C99 d) double is more precise than float and can store 64 bits 5. Which is the correct format specifier for double type value in C? a) %d b) %f c) %lf d) %LF 6. The short type represents ___. a) int b) float c) unsigned int d) short int 7. How many byte(s) does a short type take in C? a) 1 b) 2 c) 3 d) 4 8. What is the correct syntax to declare a variable in C? a) data_type variable_name; b) data_type as variable_name; c) variable_name data_type; d) variable_name as data_type; 9. How many types of qualifiers are there in C language? a) 2 b) 3 c) 4 d) 5 10. Which is/are the size qualifier(s) in C language? a) short b) long c) double d) Both A. and B 31. Which is/are the sign qualifier(s) in C language? a) signed b) unsigned c) long d) Both A. and B 12. Which is/are the type qualifier(s) in C language? a) const b) volatile c) static d) Both A. and B 13. Which is correct with respect to the size of the data types in C? a) char > int > float b) char < int < float c) int < char < float d)int < chat > float 14. Which operator is used to find the remainder of two numbers in C? a) / b) c) % d)
  • 4. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 15. Which of the following is not an arithmetic expression? a) x = 10 b) x /= 10 c) x %= 10 d) x != 10 16. Increment (++) and decrement (--) are the ___ operators in C? a) Unary b) Binary c) Ternary d) None of the above 17. Which C keyword is used to extend the visibility of variables? a) extend b) extends c) extern d) auto 18. What is the name of "&" operator in C? a) Ampersand b) And c) Address of c) None of the above 19. 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 20. 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; 21. Which of the following cannot be a variable name in C? a) volatile b) true c) friend d) export 22. What is short int in C programming? a) The basic data type of C b) Qualifier c) Short is the qualifier and int is the basic data type d) All of the mentioned 23. Functions in C Language are always _________ a) Internal b) External c) Both a & b ) External and Internal are not valid terms for functions 24. Which of the following is not a valid C variable name? a) int number; b) float rate; c) int variable_count; d) int $main; 25. Which of the following is true for variable names in C? a) Variable names cannot start with a digit b) Variable can be of any length c) They can contain alphanumeric characters as well as special characters d) Reserved Word can be used as variable name
  • 5. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word C CONDITIONAL STATEMENTS & LOOPING 1. Which of the following are valid decision-making statements in C? A) if b) switch c) nested if d) All of these 2. Decision making in the C programming language is ___. a) Repeating the same statement multiple times b) Executing a set of statements based on some condition c) Providing a name of the block of code d) All of these 3. Which of the following is a true value in C programming? a) 1 b) "includehelp" c) ! NULL d) All of these 4. Ternary operator in C programming is ___. a) if-else-if b) ? : c) ? ; ? d) None of these 5. The if statement is a conditional statement? a) True b) False 6. When the condition of if statement is false, the flow of code will ___. a) go into the if block b) Exit the program c) Continue the code after skipping the if block d) None of these 7. Which statement is required to execute a block of code when the condition is false? a) for b) if c) else d) All of these 8. Can the else statement exist without the if statement in C? a) Yes b) No 9. The if-elseif-else statement in C programming is used? a) Create multiple conditional statements b) Return values c) Loop in if-else block d) All of these 10. How many expressions can be checked using if...elseif...else statement? a) 100 b) 1 c) Infinite d) None of these 11. Is it possible to nest if-else statements in C programming? a) Yes b) No 12. Multiple values of the same variable can be tested using ___. a) switch b) for c) Function d) All of these 13. Without a break statement in switch what will happen? a) All cases will work properly b) Cases will fall through after matching the first check c) Switch will throw error d) All of these 14. When all cases are unmatched which case is matched in a switch statement? a) Default case b) First case c) No case d)None of these
  • 6. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 15. Loops in C programming are used to ___. Execute a statement based on a condition b) Execute a block of code repeatedly c)Create a variable d) None of these 16. Which of these is an exit-controlled loop? a) for b) if c) do...while d) while 17. Which statements are used to change the execution sequence? a) Loop control statement b) Function statement c) Conditional statement d) All of these 18. What will happen if the loop condition will never become false? a) Program will throw an error b) Program will loop infinitely c) Loop will not run d) None of these 19. Which of these statements is correct in case of while loop in C? a) Executes the block till the condition become false b) Is an entry controlled loop c) There might be condition when the loop will not execute at all d) All of these 20. Which loop executes the block a specific number of times? a) while loop b) for loop c) do...while loop d) All of these 21. Which of the following parts of the for loop can be eliminated in C? a) init b) condition c) increment d) All of these 22. When all parts of the for loop are eliminated, what will happen? a) For loop will not work b) Infinite for loop c) Error d) None of these 23. When the condition of the do-while loop is false, how many times will it execute the code? a) 0 b) 1 c) Infinite d) All of these 24. Can a loop be nested in C programming? a) Yes b) No 25. The continue statment cannot be used with a) for b) while c) do while d) switch 26. goto can be used to jump from main to within a function? a) TRUE b) FALSE c) May Be d) Can't Say 27. Switch statement accepts. a) int b) char c) long d) All of the above 28. Which loop is guaranteed to execute at least one time. a) for b) while c) do while d) None of the above 29. do-while loop terminates when conditional expression returns? a) One b) Zero c) Non – zero d) None of the above
  • 7. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 30. Which of the following statement about for loop is true? a) Index value is retained outside the loop b) Index value can be changed from within the loop c) Goto can be used to jump, out of the loop d) All of these STRINGS & ARRAYS 1. A string is terminated by ___. a) Newline ('n') b) Null ('0') c) Whitespace d) None of the above 2. Which format specifier is used to read and print the string using printf() and scanf() in C? a) %c b)%str c)%p d) %s 3. Which function is used to read a line of text including spaces from the user in C? a) scanf() b) getc() c) fgets() d) All of the above 4. Which function is used to concatenate two strings in C? a) concat() b) cat() c) stringcat() d) strcat() 5. Which function is used to compare two strings in C? a) strcmp() b) strcmpi() c) compare() d) cmpi() 6. Which function is used to compare two strings with ignoring case in C? a) strcmp() b) strcmpi() c) compare() d) cmpi() 7. Which is the correct syntax to declare an array in C? a) data_type array_name[array_size]; b) data_type array_name{array_size}; c) data_type array_name[]; d) All of the above 8. You can access elements of an array by ___. a) values b) indices c) memory addresses d) All of the above 9. Which is/are the correct syntax to initialize an array in C? a) data_type array_name[array_size] = {value1, value2, value3, …}; b) data_type array_name[] = {value1, value2, value3, …}; c) data_type array_name[array_size] = {}; d) Both A and B 10. Array elements are always stored in ___ memory locations. a) Random b) Sequential c) Both A and B d) None of the above 11. Let x is an integer array with three elements having value 10, 20, and 30. What will be the output of the following statement? printf("%u",x); a) Prints the value of 0th element (i.e., 10) b) Prints the garbage value c) An error occurs d) Print the address of the array (i.e., the address of first (0th) element 12. What will be the output of the following C program? #include <stdio.h> int main()
  • 8. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word { int x[5] = { 10, 20, 30 }; printf("%ld", sizeof(x)/sizeof(x[0])); return 0; } a) 3 b) 4 c) 5 d) 6 13. What will be the output of the following C program? #include <stdio.h> int main() { int x[5] = { 10, 20, 30 }; printf("%d", x[3]); return 0; } a) 0 b) 30 c) Garbage value d) Error 14. What will be the output of the following C program? #include <stdio.h> int main() { int x[5] = { 10, 20, 30 }; printf("%d", x[-1]); return 0; } a) 0 b) 10 c) Garbage value d) Error 15. If we pass an array as an argument to a function, what actually gets passed? a) Value of elements in array b) First element of the array c) Base address of the array i.e., the address of the first element d) Address of the last element of array OOPS CONCEPTS 1. Wrapping data and its related functionality into a single entity is known as _____________ a) Abstraction b) Encapsulation c) Polymorphism d) Modularity 2. How structures and classes in C++ differ? a) In Structures, members are public by default whereas, in Classes, they are private by default b) In Structures, members are private by default whereas, in Classes, they are public by default c) Structures by default hide every member whereas classes do not d) Structures cannot have private members whereas classes can have 3. What does polymorphism in OOPs mean?
  • 9. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word a) Concept of allowing overiding of functions b) Concept of hiding data c) Concept of keeping things in differnt modules/files d) Concept of wrapping things into a single unit 4. Which concept allows you to reuse the written code? a) Encapsulation b) Abstraction c) Inheritance d) Polymorphism 5. Which of the following explains Polymorphism? a) int func(int, int); float func1(float, float); b) int func(int); int func(int); c) int func(float); float func(int, int, char); d) int func(); int new_func(); 6. Which of the following shows multiple inheritances? a) A->B->C b) A->B; A->C c) A,B->C d) B->A 7. How access specifiers in Class helps in Abstraction? a) They does not helps in any way b) They allows us to show only required things to outer world c) They help in keeping things together d) Abstraction concept is not used in classes 8. C++ is ______________ a) procedural programming language b) object oriented programming language c) functional programming language d) both procedural and object oriented programming language 9. What does modularity mean? a) Hiding part of program b) Subdividing program into small independent parts c) Overriding parts of program d) Wrapping things into single unit 10. Which of the following feature of OOPs is not used in the following C++ code? class A{ int i; public: void print() {cout << "hello" << i;} } class B : public A{ int j; public: void assign (int a ) {k = a;} } a) Abstraction b) Encapsulation c) Inheritance d) Polymorphism 11. Which of the following class allows to declare only one object of it? a) Abstract class b) Virtual class c) Singleton class d) Friend class 12. Which of the following is not a type of Constructor? a) Friend constructor b) Copy constructor c) Default constructor d) Parameterized constructor 13. Which of the following is correct?
  • 10. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word a) Base class pointer object cannot point to a derived class object b) Derived class pointer object cannot point to a base class object c) A derived class cannot have pointer objects d) A base class cannot have pointer objects 14. Out of the following, which is not a member of the class? a) Static function b) Friend function c) Constant function d) Virtual function 15. What is the other name used for functions inside a class? a) Member variables b) Member functions c) Class functions d) Class variables 16. Which of the following cannot be a friend? a) Function b) Class c) Object d) Operator function 17. Why references are different from pointers? a) A reference cannot be made null b) A reference cannot be changed once initialized c) No extra operator is needed for dereferencing of a reference d) All of the mentioned 18. Which of the following provides a programmer with the facility of using object of a class inside other classes? a) Inheritance b) Composition c) Abstraction d) Encapsulation 19. How many types of polymorphism are there in C++? a) 1 b) 2 c) 3 d) 4 20. How run-time polymorphisms are implemented in C++? a) Using Inheritance b) Using Virtual functions c) Using Templates d) Using Inheritance and Virtual functions 21. How compile-time polymorphisms are implemented in C++? a) Using Inheritance b) Using Virtual functions c) Using Templates d) Using Inheritance and Virtual functions 22. Which of the following is an abstract data type? a) int b) float c) class d) string 23. Which concept means the addition of new components to a program as it runs? a) Data hiding b) Dynamic binding c) Dynamic loading d) Dynamic typing 24. Which of the following explains the overloading of functions? a) Virtual polymorphism b) Transient polymorphism c) Ad-hoc polymorphism d) Pseudo polymorphism 25. Which of the following approach is used by C++? a) Top-down b) Bottom-up c) Left-right d) Right-left 26. Which operator is overloaded for a cout object? a) >> b) << c) < d) >
  • 11. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 27. Which of the following cannot be used with the virtual keyword? a) Class b) Member functions c) Constructors d) Destructors 28. Which concept is used to implement late binding? a) Virtual functions b) Operator functions c) Constant functions d) Static functions 29. Which of the following is correct? a) C++ allows static type checking b) C++ allows dynamic type checking. c) C++ allows static member function to be of type const. d) C++ allows both static and dynamic type checking 30. Which of the following supports the concept that reusability is a desirable feature of a language? a) It reduces the testing time b) It reduces maintenance cost c) It decreases the compilation time d) It reduced both testing and maintenance time 31. Which of the following is a static polymorphism mechanism? a) Function overloading b) Operator overloading c) Templates d) All of the mentioned 32. Which of the following is true? I) All operators in C++ can be overloaded. II) The basic meaning of an operator can be changed. a) I only b) II only c) Both I and II d) Neither I nor II 33. Which of the following is not a type of inheritance? a) Multiple b) Multilevel c) Distributive d) Hierarchical 34. What happens if a class does not have a name? a) It will not have a constructor b) It will not have a destructor c) It is not allowed d) It will neither have a constructor or destructor 35. Which of the following statement is true? I) In Procedural programming languages, all function calls are resolved at compile-time II) In Object Oriented programming languages, all function calls are resolved at compile-time a) I only b) II only c) Both I and II d) Neither I nor II 36. Which members are inherited but are not accessible in any case? a) Private b) Public c) Protected d) Both private and protected 37. Which of the following is correct? a) Friend functions can access public members of a class b) Friend functions can access protected members of a class c) Friend functions can access private members of a class d) All of the mentioned 38. Which of the following is correct in C++? a) Classes cannot have protected data members b) Structures can have member functions c) Class members are public by default d) Structure members are private by default 39. Which of the following is used to make an abstract class?
  • 12. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word a) By using virtual keyword in front of a class declaration b) By using an abstract keyword in front of a class declaration c) By declaring a virtual function in a class d) By declaring a pure virtual function in a class 40. Which of the following is correct? a) A class is an instance of its objects b) An object is an instance of its class c) A class is an instance of the data type that the class have d) An object is an instance of the data type of the class Fundamentals of C++ 1. Who created C++? a) Bjarne Stroustrup b) Dennis Ritchie c) Ken Thompson d) Brian Kernighan 2. C++ Language developed at _________? a) AT & T's Bell Laboratories of USA in 1972 b) Sun Microsystems in 1973 c) Cambridge University in 1972 d) AT & T's Bell Laboratories of USA in 1979 3. Which one of the following is a keyword? a) Size b) Key c) Jump d) Switch 4. ____ is the smallest individual unit in a program. a) Variable b) Control c) Character d) Token 5. Which of the following is the correct syntax of including a user defined header files in C++? a) #include <userdefined.h> b) #include <userdefined> c) #include “userdefined” d) #include [userdefined] 6. Which of the following is a correct identifier in C++? a) 7var_name b) 7VARNAME c) VAR_1234 d) $var_name 7. Which of the following is called address operator? a) * b) & c) _ d) % 8. C++ is _______ type of programming language.? a) Object Oriented b) Procedural c) Bit level language d) Functional 9. Which of the following is used for comments in C++? a) // comment b) /* comment */ c) both // comment or /* comment */ d) // comment */ 10. What are the actual parameters in C++? a) Parameters with which functions are called b) Parameters which are used in the definition of a function c) Variables other than passed parameters in a function d) Variables that are never used in the function
  • 13. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 11. What are the formal parameters in C++? a) Parameters with which functions are called b) Parameters which are used in the definition of the function c) Variables other than passed parameters in a function d) Variables that are never used in the function 12. Which function is used to read a single character from the console in C++? a) cin.get(ch) b) getline(ch) c) read(ch) d) scanf(ch) 13. Which function is used to write a single character to console in C++? a) cout.put(ch) b) cout.putline(ch) c) write(ch) d) printf(ch) 14. What is a constant that contains a single character enclosed within single quotes? a) Numeric b) Fixed c) Character d) Floating Point 15. A C++ code line ends with ___ a) A Semicolon (;) b) A Fullstop(.) c) A Comma (,) d) A Slash (/) 16. What are the escape sequences? a) Set of characters that convey special meaning in a program b) Set of characters that whose use are avoided in C++ programs c) Set of characters that are used in the name of the main function of the program d) Set of characters that are avoided in cout statements 17. Which of the following escape sequence represents carriage return? a) r b) n c) nr d) c 18. Which of the following escape sequence represents tab? a) t b) tr c) b d) a 19. Which of the following is called insertion/put to operator? a) >> b) << c) > d) < 20. Which of the following is called extraction/get from operator? a) << b) >> c) > d) < 21. A language which has the capability to generate new data types are called ________________ a) Extensible b) Overloaded c) Encapsulated d) Reprehensible 22. Which of the following is not a fundamental type is not present in C but present in C++? a) int b) float c) bool d) void 23. What is the size of a boolean variable in C++? a) 1 bit b) 1 byte c) 4 bytes d) 2 bytes 24. Which of the following is C++ equivalent for scanf()? a) cin b) cout c) print d) input 25. Which of the following is C++ equivalent for printf()? a) cin b) cout c) print d) input
  • 14. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 26. Which of the following is an exit-controlled loop? a) for b) while c) do-while d) all of the mentioned 27. Which of the following is the correct difference between cin and scanf()? a) both are the same b) cin is a stream object whereas scanf() is a function c) scanf() is a stream object whereas cin is a function d) cin is used for printing whereas scanf() is used for reading input 28. Which of the following is an entry-controlled loop? a) for b) while c) do-while d) both while and for 29.In which part of the for loop termination condition is checked? for(I;II;III) a) I b) II c) III d) IV 30. Which of the following is the scope resolution operator? a) . b) * c) :: d) ~ Constants & Data Types 1. The constants are also called as a) Const b) preprocessor c) literals d) none of these 2. What are the parts of the literal constants? a) integer numerals b) floating-point numerals c) strings and boolean values d) all of the mentioned 3. What is the size of wchar_t in C++? a) 2 b) 4 c) 2 or 4 d) Based on the number of bits in the system 4. Pick the odd one out. a) array type b) character type c) boolean type d) integer type 5. Which data type is used to represent the absence of parameters? a) int b) short c) void d) float 6. What does ‘a’ escape code represent? a) alert b) backslash c) tab d) form feed 7. How the constants are declared? a) const keyword b) #define preprocessor c) both a and b d) None of these 8. Which type is best suited to represent the logical values? a) integer b) Boolean c) character d) float 9. Identify the user-defined types from the following? a) enumeration b) classes c) both enumeration and classes d) int
  • 15. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 10. Which of the following statements are true? int f (float) a) f is a function taking an argument of type int and returning a floating point number b) f is a function taking an argument of type float and returning an integer c) f is a function of type float d) f is a function of type int 11. The value 132.54 can be represented using which data type? a) double b) void c) int d) bool 12. When a language has the capability to produce new data type mean, it can be called as a) overloaded b) extensible c) encapsulated d) reprehensible 13. Pick the odd one out. a) integer, character, boolean, floating b) enumeration, classes c) integer, enum, void d) arrays, pointer, classes 14. How many characters are specified in the ASCII scheme? a) 64 b) 128 c) 256 d) 24 15. Given the variables p, q are of char type and r, s, t are of int type. Select the right statement? 1. t = (r * s) / (r + s); 2. t = (p * q) / (r + s); a) 1 is true but 2 is false b) 1 is false and 2 is true c) both 1 and 2 are true d) both 1 and 2 are false 16. Which of the following belongs to the set of character types? a) char b) wchar_t c) only a d) both wchar_t and char 17. How do we represent a wide character of the form wchar_t? a) L’a’ b) l’a’ c) L[a] d) la 18. In C++, what is the sign of character data type by default? a) Signed b) Unsigned c) Implementation dependent d) Unsigned Implementation 19. Is the size of character literals different in C and C++? a) Implementation defined b) Can’t say c) Yes, they are different d) No, they are not different 20. Suppose in a hypothetical machine, the size of char is 32 bits. What would sizeof(char) return? a) 4 b) 1 c) Implementation dependent d) Machine dependent 21. What constant defined in <climits> header returns the number of bits in a char? a) CHAR_SIZE b) SIZE_CHAR c) BIT_CHAR d) CHAR_BIT 22. The size_t integer type in C++ is? a) Unsigned integer of at least 64 bits b) Signed integer of at least 16 bits c) Unsigned integer of at least 16 bits d) Signed integer of at least 64 bits
  • 16. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 23. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int x = -1; unsigned int y = 2; if (x > y) { cout << "x is greater: " ; } else { cout << "y is greater: " ; } return 0; } a) x is greater b) y is greater c) implementation defined d) arbitrary 24. Which of these expressions will return true if the input integer v is a power of two? a) (v | (v + 1)) == 0; b) (~v & (v – 1)) == 0; c) (v | (v – 1)) == 0; d) (v & (v – 1)) == 0; 25. What is the value of the following 8-bit integer after all statements are executed? 1. int x = 1; 2. x = x << 7; 3. x = x >> 7; a) 1 b) -1 c) 127 d) Implementation defined 26. Which of these expressions will make the rightmost set bit zero in an input integer x? a) x = x | (x-1) b) x = x & (x-1) c) x = x | (x+1) d) x = x & (x+2) 27. Which of these expressions will isolate the rightmost set bit? a) x = x & (~x) b) x = x ^ (~x) c) x = x & (-x) d) x = x ^ (-x) 28. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int x = 8; cout << "ANDing integer 'x' with 'true' : " << x && true; return 0; } a) ANDing integer ‘x’ with ‘true’ :8 b) ANDing integer ‘x’ with ‘true’ :0 c) ANDing integer ‘x’ with ‘true’ :1 d) ANDing integer ‘x’ with ‘true’ :9 29. 0946, 786427373824, ‘x’ and 0X2f are _____ _____ ____ and _____ literals respectively. a) decimal, character, octal, hexadecimal b) octal, hexadecimal, character, decimal c) hexadecimal, octal, decimal, character d) octal, decimal, character, hexadecimal
  • 17. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 30. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int i = 3; int l = i / -2; int k = i % -2; cout << l << k ; return 0; } a) compile time error b) -1 1 c) 1 -1 d) implementation defined Decision making & Loops 1. How many sequences of statements present in C++? a) 4 b) 3 c) 5 d) 6 2. Decision Control statements in C++ can be implemented using a) if b) if-else c) Conditional Operator d) All of the above 3. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { if (0) { cout << "Hello" ; } else { cout << "Good Bye" ; } return 0; } a) Hello b) Good Bye c) HelloGood bye d) Compilation Error 4. if you have to make decision based on multiple choices, which of the following is best suited? a) if b) if-else c) if-else-if d) All of the above 5. Can we use string inside switch statement? a) Yes b) No 6. In situations where we need to execute body of the loop before testing the condition, we should use_____. a) For loop b) while loop c) do-while loop d) nested for loop
  • 18. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 7. Loops in C++ Language are implemented using? a) While loop b) For loop c) Do while loop d) All of the above 8. While loop is faster in C++ Language, for, while or do-while? a) For b) while c) do-while d) All work ate same speed 9. What is the way to suddenly come out of or quit any loop in C++? a) continue; statement b) break; statement c) leave; statement d) quit; statement 10. Which of the following can replace a simple if -wlsw construct? a) Ternary operator b) while loop c) do-while loop d) fop loop 11. The if...else statement can be replaced by which operator? a) Bitwise operator b) Conditional operator c) Multiplicative operator d) Addition operator 12. The switch statement is also called as? a) choosing structure b) selective structure c) certain structure d) bitwise structure 13. Choose a correct C++ for loop syntax. a) for(initalization; condition; inc/dec){ // statements }; b) for(declaration; condition; incrementoperation){ // statements }; c) for(declaration; incrementoperation; condition){ // statements }; d) for(initalization; condition; incrementoperation){ // statements }; 14. Choose a correct C++ do while syntax. a) dowhile(condition){ // statements }; b) do while(condition){ // statements }; c) do{ // statements }while(condition) d) do{ // statements }while(condition); 15. Choose a correct C++ Statement. a) a++ is (a= a+1) POST INCREMENT operator b) a-- is (a = a-1) POST DECREMENT operator. --a is (a = a-1) PRE DECREMENT operator c) ++a is (a = a+1) PRE INCREMENT operator d) All of the above. 16. Which of the following is an entry-controlled loop? a) For loop b) while loop c) do-while loop d) both b & c 17. Which of the following is an exit-controlled loop? a) While loop b) For loop c) Do while loop d) both b & c 18. Which of the following is most suitable for a menu-dricen program? a) For b) while c) do-while d) All of the above 19. Consider the following loop: for(int i = 0; i<5; i++); a) It will give compilation error. b) 5 c) 6 d) Some Garbage value 20. A switch construct can be used with which of the following types of variable? a) int b) int, char c) int, float, char d) Any basic datatype
  • 19. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 21. The destination statement for the goto label is identified by what label? a) $ b) @ c) * d) : 22. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int n ; for (n = 5; n < 0; n--) { cout << n; if (n == 3) break; } return 0; } a) 543 b) 54 c) 5432 d) 53 23. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 10; if (a = 15) { time; cout << a; if (n == 3) goto time; } break; return 0; } a) 1010 b) 10 c) infinitely print 10 d) compile time error 24. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int n = 15; for (; ;) cout << n; return 0; } a) error b) 15 c) infinite times of printing n d) none of the mentioned 25. Which looping process is best used when the number of iterations is known?
  • 20. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word a) While loop b) For loop c) Do while loop d) all looping processes require that the iterations be known 26. How many types of loops are there in C++? a) 4 b) 2 c) 3 d) 1 27. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int i ; for (i = 0; i < 10; i++); { cout << i; } return 0; } a) 0123456789 b) 10 c) 012345678910 d) compile time error 28. Which of the following must be present in switch construct? a) Expression in ( ) after switch b) default c) case followed by value d) All of the above 29. What is the effect of writing a break statement inside a loop? a) It cancels remaining iterations. b) It skips a particular iteration. c) The program terminates immediately. d) Loop counter is reset. 30. The break statement causes an exit a) fromthe innermost loop only. b) only from the innermost switch. c) from all loops & switches. d) from the innermost loop or switch. Operators 1. Which operator is having the right to left associativity in the following? a) Array subscripting b) Function call c) Addition and subtraction d) Type cast 2. What are the essential operators in c++? a) + b) | c) <= d) All of the mentioned 3. In which direction does the assignment operation will take place? a) left to right b) right to left c) top to bottom d) bottom to top 4. Pick out the compound assignment statement. a) a = a – 5 b) a = a / b c) a -= 5 d) a = a + 5 5. What is the associativity of add(+); ? a) right to left b) left to right c) right to left & left to right d) top to bottom
  • 21. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 6. What is the name of | operator? a) sizeof b) or c) and d) modulus 7. Which operator is having the highest precedence in c++? a) array subscript b) Scope resolution operator c) static_cast d) dynamic_cast 8. Which operator is having the highest precedence? a) postfix b) unary c) shift d) equality 9. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a, b; a = 10; b = 4; a = b; b = 7; cout << "a: " << a; cout << "nb: " << b; return 0; } a) a:4 b:7 b) a:10 b:4 c) a:4 b:10 d) a:4 b:6 10. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a, b, c; a = 2; b = 7; c = (a > b) ? a : b; cout << "c: " << c; return 0; } a) 2 b) 7 c) 9 d) 14 11. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a; a = 5 + 3 * 5; cout << "a: " << a; return 0; } a) 35 b) 20 c) 25 d) 30
  • 22. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 12. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 0; int b = 10; a = 2; b = 7; if (a && b) { cout << "true: " << endl; } else { cout << "false: " << endl; } return 0; } a) true b) false c) error d) 10 13. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 5, b = 6, c, d; c = a, b; d = (a ,b); cout << c << " " << d; return 0; } 6 a) 5 5 b) 6 7 c) 6 8 d) 6 14. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int i, j; j = 10; i = (j++, j + 100, 999 + j); cout << i; return 0; } a) 1000 b) 11 c) 1010 d) 1001 15. What is the use of dynamic_cast operator? a) it converts virtual base class to derived class b) it converts the virtual base object to derived objects c) it will convert the operator based on precedence d) it converts the virtual base object to derived class 16. What will be the output of the following C++ code?
  • 23. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word #include <iostream> using namespace std; int main() { int x, y; x = 5; y = ++x * ++x; cout << x << y; y = x++ * ++x; cout << x << y; return 0; } a) 749735 b) 736749 c) 367497 d) 367597 18. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 5, b = 6, c; c = (a > b) ? a : b; cout << c; return 0; } a) 6 b) 5 c) 4 d) 7 19. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { double a = 21.09399; float b = 10.20; int c, d; c = (int) a; d = (int) b; cout << c << " " << d; return 0; } 10 a) 20 21 b) 10 10 c) 21 20 d) 10 20. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 20, b = 10, c = 15, d = 5; int e; e = a + b * c / d; cout << e << endl; return 0; } a) 50 b) 60 c) 70 d) 90
  • 24. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 21. What is this operator called "?:" ? a) condtional b) relational c) casting operator d) unrelational C++ Functions 1. Where does the execution of the program starts? a) user-defined function b) main function c) void function d) else function 2. What are mandatory parts in the function declaration? a) return type, function name b) return type, function name, parameters c) parameters, function name d) parameters, variables 3. which of the following is used to terminate the function declaration? a) : b) ) c) ; d) ] 4. How many can max number of arguments present in function in the c99 compiler? a) 99 b) 90 c) 102 d) 127 5. Which is more effective while calling the functions? a) call by value b) call by reference c) call by pointer d) call by object 6. What will be the output of the following C++ code? #include <iostream> using namespace std; void car{ cout << "Audi R8"; } int main() { car(); return 0; } a) Audi R8 b) Audi R8Audi R8 c) compile time error d) runtime error 7. What will be the output of the following C++ code? #include <iostream> using namespace std; void fun(int x, int y){ x = 20; y = 10; } int main() { int x = 10; fun (x, x); cout << x; return 0; } a) 10 b) 20 c) compile time error d) 30
  • 25. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 8. What happens to a function defined inside a class without any complex operations (like looping, a large number of lines, etc)? a) It becomes a virtual function of the class b) It becomes a default calling function of the class c) It becomes an inline function of the class d) The program gives an error 9. What is the scope of the variable declared in the user defined function? a) whole program b) only inside the {} block c) the main function d) header section 10. How many minimum number of functions should be present in a C++ program for its execution? a) 0 b) 1 c) 2 d) 3 11. Which of the following is the default return value of functions in C++? a) int b) char c) float d) void 12. What is an inline function? a) A function that is expanded at each call during execution b) A function that is called during compile time c) A function that is not checked for syntax errors d) A function that is not checked for semantic analysis 13. In which of the following cases inline functions may not word? i) If the function has static variables. ii) If the function has global and register variables. iii) If the function contains loops iv) If the function is recursive a) i, iv b) iii, iv c) ii, iii, iv d) i, iii, iv 14. When we define the default values for a function? a) When a function is defined b) When a function is declared c) When the scope of the function is over d) When a function is called 15. Where should default parameters appear in a function prototype? a) To the rightmost side of the parameter list b) To the leftmost side of the parameter list c) Anywhere inside the parameter list d) Middle of the parameter list 16. If an argument from the parameter list of a function is defined constant then _______________ a) It can be modified inside the function b) It cannot be modified inside the function c) Error occurs d) Segmentation fault 17. What will be the output of the following C++ code? #include <iostream> using namespace std; int fun(int x = 0, int y = 0, int z){ return (x + y + z); } int main() { cout << fun(10); return 0; } a) 10 b) 0 c) Error d) Segmentation fault
  • 26. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 18. What will be the output of the following C++ code? #include <iostream> using namespace std; int fun(int = 0, int = 0); int main() { cout << fun(5); return 0; } int fun(int x, int y){ return (x + y); } a) -5 b) 0 c) 10 d) 5 19. Which of the following feature is used in function overloading and function with default argument? a) Encapsulation b) Polymorphism c) Abstraction d) Modularity 20. An inline function is expanded during ______________ a) compile-time b) run-time c) never expanded d) end of the program C++ Arrays & Strings 1. Which of the following correctly declares an array? a) int array[10]; b) int array; c) array{10}; d) array array[10]; 2. What is the index number of the last element of an array with 9 elements? a) 9 b) 8 c) 0 d) Programmer-defined 3. What is the correct definition of an array? a) An array is a series of elements of the same type in contiguous memory locations b) An array is a series of element c) An array is a series of elements of the same type placed in non-contiguous memory locations d) An array is an element of the different type 4. Which of the following gives the memory address of the first element in array? a) array[0]; b) array[1]; c) array(2); d) array; 5. Which of the following accesses the seventh element stored in array? a) array[6]; b) array[7]; c) array(7); d) array; 6. What is the difference between unsigned int length() and unsigned int size()? a) Returns a different value b) They are same c) Returns a different value but they are same d) Returns a length 7. Which header file is used to manipulate the string? a) iostream b) iomanip c) string d) container
  • 27. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 8. What will be the output of the following C++ code? #include <iostream> using namespace std; int array1[] = {1200, 200, 2300, 1230, 1543}; int array2[] = {12, 14, 16, 18, 20}; int temp, result = 0; int main() { for (temp = 0; temp < 5; temp++){ result += array1[temp]; } for (temp = 0; temp < 4; temp++){ result += array2[temp]; } cout << result; return 0; } a) 6553 b) 6533 c) 6522 d) 12200 9. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int array[] = {0, 2, 4, 6, 7, 5, 3}; int n, result = 0; for (n = 0; n < 8; n++){ result += array[n]; } cout << result; return 0; } a) 25 b) 26 c) 27 d) 21 10. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 5, b = 10, c = 15; int arr[3] = {&a, &b, &c}; cout << *arr[*arr[1] - 0]; return 0; } a) 15 b) 18 c) garbage value d) compile time error 11. How many maximum number of parameters does a string constructor can take? a) 1 b) 2 c) 3 d) 4 12. Which constant member functions does not modify the string? a) bool empty() b) assign c) append d) delete
  • 28. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 13. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { char str[5] = "ABC"; cout << str [3]; cout << str; return 0; } a) ABC b) ABCD c) AB d) AC 14. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { char array[] = [10, 20, 30]; cout << -2 [array]; return 0; } a) -15 b) -30 c) compile time error d) garbage value 15. What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main() { string str {"Steve jobs"}; cout << str.capacity() << "n"; return 0; } a) 9 b) 10 c) 11 d) Not Fix 16. Wht will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main() { string str {"Steve jobs founded the apple"}; string str {"apple"}; unsigned found = str.find(str2); if (found != string :: npos) cout << found << "n"; return 0; } a) apple b) 12 c) 23 d) Steve jobs founded the 17. How many parameters can a resize method take? a) 1 b) 2 c) 1 or 2 d) 2
  • 29. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 18. What will be the output of the following C++ code? #include <iostream> #include <cstring> #include <string> using namespace std; int main() { string str {"Steve jobs"}; char * cstr = new char [str.length() + 1]; strcpy (cstr, str.c_str()); char * p = strtok (cstr, " "); while (p != 0) { cout << p << "n"; p = strtok(NULL, " "); } delete[] cstr; return 0; } a) Steve jo b) Steve jobs c) Steve jobs d) Steve jo 19. What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main() { string str {"Steve jobs"}; unsigned long int found = str.find_first_of("aeiou"); while (found != string :: npos) { str[found] = '*'; found = str.find_first_of("aeiou", found + 1); } cout << str << "n"; return 0; } a) Steve b) jobs c) St*v* j*bs d) St*v* 20. Which of the following is correct about remove_extent() function? a) Removes the given dimension from an array b) Removes the first dimension from the right of the array c) Removes the first dimension from the left of the array d) Removes the last dimension from the left of the array 21. What is the use of is_array() function in C++? a) To check if a variable is array type or not b) To check if a variable is 1-D array type or not c) To check if a variable is 2-D array type or not d) To check if a variable is 1-D or 2-D array type or not
  • 30. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 22. Which of the header file is used for array type manipulation? a) <array> b) <type_traits> c) <iostream> d) std namespace 23. What is the use of is_same() function in C++? a) To check if a variable is array type or not b) To check whether two variables have the same characteristics c) To check if two variable is of array type or not d) To check whether two variables are different or not 24. Which of the following is correct about extent() function? a) Returns how many elements are in array currently b) Returns the size of the 1st dimension c) Returns how many total elements can be stored in an array d) Returns the size of a given dimension 25. What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main() { cout << is_same <int, char> :: value; cout << is_same <char [10], char [10]> :: value; cout << is_same <char * [10], string]> :: value; return 0; } a) 011 b) 101 c) 010 d) 110 26. What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main() { cout << rank <int [10]> :: value; cout << rank <char [10] [10]> :: value; cout << rank < string [10] [10] [10]> :: value; return 0; } a) 111 b) 123 c) 321 d) 121 27. What is the use of rank() function in C++? a) Returns size of each dimension b) Returns how many total elements can be stored in an array c) Returns how many elements are in array currently d) Returns the dimension of an array 28. Which of the following is correct about remove_all_extents() function? a) Removes the all dimension from an array b) Removes the first dimension from the left of the array c) Removes the first dimension from the right of the array d) Removes the last dimension from the left of the array
  • 31. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 29. What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main() { cout << is_array <int> :: value; cout << is_array <char [10]> :: value; cout << is_array <string]> :: value; return 0; } a) 010 b) 101 c) 001 d) 110 30. What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main() { cout << extent < string [10][20][30], 0> :: value; cout << extent < string [10][20][30], 1> :: value; cout << extent < string [10][20][30], 2> :: value; return 0; } a) 101010 b) 102030 c) 302010 d) 102010 Structures 1. What will happen when the structure is declared? a) it will not allocate any memory b) it will allocate the memory c) it will be declared and initialized d) it will be declared 2. What will be the output of the following C++ code? #include <iostream> #include <string.h> using namespace std; int main() { int student{ int num; char name[25]; } student stu; stu.num = 123; strcpy(stu.num, "john"); cout << stu.num << endl; cout << stu.name << endl; return 0; } a) 123 john b) john john c) compile time error d) runtime error
  • 32. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 3. What will be the output of the following C++ code? #include <iostream> using namespace std; struct Time{ int hours, minutes, seconds; } int toSeconds(Time now); int main() { Time t; t.hours = 5; t.minutes = 30; t.seconds = 45; cout << "Total seconds: " << toSeconds(t) << endl; return 0; } int toSeconds (Time now){ return 3600 * now.hours + 60 * now.minutes + now.seconds; } a) 19845 b) 20000 c) 15000 d) 19844 4. The data elements in the structure are also known as what? a) objects b) members c) data d) objects & data 5. What will be used when terminating a structure? a) : b) } c) ; d) ;; 6. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { struct ShoeType{ string style; double price; }; ShoeType shoe1, shoe2; shoe1.style = "Adidas"; shoe1.price = 9.99; cout << shoe1.style << "$" << shoe1.price; shoe2 = shoe1; shoe2.price = shoe2.price / 9; cout << shoe2.style << "$" << shoe2.price; return 0; } a) Adidas $ 9.99Adidas $ 1.11 b) Adidas $ 9.99Adidas $ 9.11 c) Adidas $ 9.99Adidas $ 11.11 d) Adidas $ 11.11Adidas $ 11.11 7. The declaration of the structure is also called as? a) structure creator b) structure signifier c) structure specifier d) structure creator & signifier
  • 33. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 8. What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec{ int a; char b; }; int toSeconds(Time now); int main() { struct sec s = {25, 50}; struct sec *ps = (struct sec *) &s; cout << ps-> a << ps-> b ; return 0; } a) 252 b) 253 c) 254 d) 262 9. Which of the following is a properly defined structure? a) struct {int a;} b) struct a_struct {int a;} c) struct a_struct int a; d) struct a_struct {int a;}; 10. Which of the following accesses a variable in structure *b? a) b->var; b) b.var; c) b-var; d) b>var; C++ Pointers 1. What does the following statement mean? int (*fp) (char*); a) pointer to a pointer b) pointer to an array of chars c) pointer to function taking a char* argument and returns an int d) function taking a char* argument and returning a pointer to int 2. The operator used for dereferencing or indirection is ____ a) * b) & c) -> d) –>> 3. Choose the right option. string* x, y; a) x is a pointer to a string, y is a string b) y is a pointer to a string, x is a string c) both x and y are pointers to string types d) y is a pointer to a string 4. Which one of the following is not a possible state for a pointer. a) hold the address of the specific object b) point one past the end of an object c) zero d) point to a type 5. Which of the following is illegal? a) int *ip; b) string s, *sp = 0; c) int i; double* dp = &i; d) int *pi = 0; 6. 8. The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char and returns a pointer to a pointer to a integer is ____________ a) int **fun(float**, char**) b) int *fun(float*, char*) c) int **fun(float*, char**) d) int ***fun(*float, **char)
  • 34. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 7. What will happen in the following C++ code snippet? int a =100, b =200; int *p = &a, *q = &b ; p = q a) b is assigned to a b) p now points to b c) a is assigned to b d) q now points to a 8. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 5, b = 10, c = 15; int *arr[] = {&a, &b, &c}; cout << arr[1]; return 0; } a) 5 b) 10 c) 15 d) it will return some random number 9. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { char arr[20]; int i; for (i = 0; i < 10; i++) *(arr + i) = 65 + i; *(arr + i) = '0'; cout << arr; return 0; } a) ABCDEFGHIJ b) AAAAAAAAAA c) JJJJJJJJ d) AAAAAAJJJJ 10. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { char *ptr; char str[] = 'abcdefg'; ptr = str; ptr += 5; cout << ptr; return 0; } a) fg b) cdef c) defg d) abcd 11. What is the meaning of the following declaration? int (*p [5]) (); a) p is pointer to function b) p is array of pointer to function c) p is pointer to such function which return type is the array d) p is pointer to array of function
  • 35. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 12. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24}; cout << *(a[1] + 2) << * (*(a + 1) + 2) << [1[a]]; return 0; } a) 15 18 21 b) 21 21 21 c) 24 24 24 d) Compile time error 13. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int arr[] = {4, 5, 6, 7}; int *p = (arr + 1); cout << *p; return 0; } a) 4 b) 5 c) 6 d) 7 14. What will happen in the following C++ code snippet? #include <iostream> using namespace std; int main() { int arr[] = {4, 5, 6, 7}; int *p = (arr + 1); cout << arr; return 0; } a) 4 b) 5 c) address of arr d) 7 15. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int numbers[5]; int *p; p = numbers; *p = 10; p++; *p = 20; p = numbers[2]; *p = 30; p = numbers + 3; *p = 40; p = numbers; *(p + 4) = 50; for (int n = 0; n < 5; n++){ cout << numbers[n] << ","; } return 0; } a) 10,20,30,40,50, b) 1020304050 c) compile error d) runtime error
  • 36. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 16. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int arr[] = {4, 5, 6, 7}; int *p = (arr + 1); cout << *arr + 9; return 0; } a) 12 b) 5 c) 13 d) error 17. What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int i; const char *arr[] = {"c", "c++", "java", "VBA"}; const char *(*ptr)[4] = &arr; cout << ++(*ptr)[2]; return 0; } a) ava b) java c) c++ d) compile time error 18. The void pointer can point to which type of objects? a) int b) float c) double d) all of the mentioned 19. When does the void pointer can be dereferenced? a) when it doesn’t point to any value b) when it cast to another type of object c) using delete keyword d) using shift keyword 20. What is size of generic pointer in C++ (in 32-bit platform)? a) 2 b) 4 c) 8 d) 0 C++ File Management 1. Which header file is required to use file I/O operations? a) <ifstream> b) <ostream> c) <fstream> d) <iostream> 2. Which stream class is to only write on files? a) ofstream b) ifstream c) iostream d) fstream 3. Which of the following is used to create an output stream? a) ofstream b) ifstream c) iostream d) fstream 4. Which of the following is used to create a stream that performs both input and output operations? a) ofstream b) ifstream c) iostream d) fstream
  • 37. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 5. Which of the following is not used as a file opening mode? a) ios::trunk b) ios::binary c) ios::in d) ios::ate 6. Which of the following statements are correct? 1) It is not possible to combine two or more file opening mode in open() method. 2) It is possible to combine two or more file opening mode in open() method. 3) ios::in and ios::out are input and output file opening mode respectively. a) 1, 3 b) 2, 3 c) 3 only d) 1, 2 7. By default, all the files in C++ are opened in _________ mode. a) Text b) Binary c) ISCII d) VTC 8. What is the use of ios::trunc mode? a) To open a file in input mode b) To open a file in output mode c) To truncate an existing file to half d) To truncate an existing file to zero 9. Which of the following is the default mode of the opening using the ofstream class? a) ios::in b) ios::out c) ios::app d) ios::trunc 10. What is the return type open() method? a) int b) char c) bool d) float 11. Which of the following is not used to seek file pointer? a) ios::set b) ios::end c) ios::cur d) ios::beg 12. Which of the following is the default mode of the opening using the ifstream class? a) ios::in b) ios::out c) ios::app d) ios::trunc 13. Which of the following is the default mode of the opening using the fstream class? a) ios::in b) ios::out c) ios::in|ios::out d) ios::trunc 14. Which function is used in C++ to get the current position of file pointer in a file? a) tell_p() b) get_pos() c) get_p() d) tell_pos() 15. Which function is used to reposition the file pointer? a) moveg() b) seekg() c) changep() d) go_p() 16. Which of the following is used to move the file pointer to start of a file? a) ios::beg b) ios::start c) ios::cur d) ios::first 17. It is not possible to combine two or more file opening mode in open () method. a) True b) False c) May be d) None of these 18. Which of these is the correct statement about eof() ? a) Returns true if a file open for reading has reached the next character. b) Returns true if a file open for reading has reached the next word. c) Returns true if a file open for reading has reached the end. d) Returns true if a file open for reading has reached the middle.
  • 38. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 19. Which of the following true about FILE *fp a) FILE is a structure and fp is a pointer to the structure of FILE type b) FILE is a buffered stream c) FILE is a stream d) FILE is a keyword in C for representing files and fp is a variable of FILE type 20. Which of the following methods can be used to open a file in file handling? a) Using Open ( ) b) Constructor method c) Destructor method d) Both A and B 21. Which operator is used to insert the data into file? a) >> b) << c) < d) None of the above 22. Which is correct syntax? a) myfile:open ("example.bin", ios::out); b) myfile.open ("example.bin", ios::out); c) myfile::open ("example.bin", ios::out); d) myfile.open ("example.bin", ios:out); 23. In fopen(), the open mode "wx" is sometimes preferred "w" because. i) Use of wx is more efficient. ii) If w is used, old contents of file are erased and a new empty file is created. When wx is used, fopen() returns NULL if file already exists. a) Only I b) Only ii c) Both i & ii d) None of the above 24. ios::trunc is used for ? a) If the file is opened for output operations and it already existed, no action is taken. b) If the file is opened for output operations and it already existed, then a new copy is created. c) None of the above d) If the file is opened for output operations and it already existed, its previous content is deleted and replaced by the new one. 25. What is the output of this program? #include <iostream> #include <string> using namespace std; int main() { char fine, course; cout << "Enter a word: "; fine = cin.get(); cin.sync(); course = cin.get(); cout << fine << endl; cout << course << endl; return 0; } a) course b) fine c) None of the mentioned d) Returns fine 2 letter or number from the entered word 26. Which of the following is not a file opening mode ____ . a) ios::ate b) ios::nocreate c) ios::noreplace d) ios::truncate 27. Due to ios::trunc mode, the file is truncated to zero length. a) True b) False
  • 39. S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word S.ANUSUYA, Assistant Professor in CS (AI & DS), Sri Vasavi College, SFW CP- C & C++ I Word 28. Which member function is used to determine whether the stream object is currently associated with a file? a) is_open b) Buf c) String d) None of the above 29. getc() returns EOF when a) End of files is reached b) When getc() fails to read a character c) Both A & B d) None of the above 30. If we have object from fstream class, then what is the default mode of opening the file? a) ios::in|ios::out b) ios::in|ios::out|ios::trunk c) ios::in|ios::trunk d) Default mode depends on compiler