1.
Which one of the following programming language considered as second generation
language?
a. Assembly language c. Procedural language
b. Machine language d. Object oriented programming language
Explanation : Assembly language is second generation while machine language is first
generation
2. Machine specific or dependent languages are ______.
a. Low level programming Languages c. Basic and Java programming
b. High level programming Languages d. C and C++ programming
Explanation: Low level programming languages are machine dependent while the others
are high level programming languages
3. The process of writing a program in small independent parts called modules is ___.
a. Procedural programming c. Object oriented programming
b. Structured programming d. Sequential programming
Explanation: It is structured programming this can be considered as subset of
procedural programming and avoid the reliance on use of Go to or Jump statements to
reuse code.
4. A program should be in a way that can be modified or upgraded when the need
arises. This property best describe by ______
a. Portable c. Reliable
b. Efficient d. Maintainable
Explanation: It is maintainable
Portable- usable in another type of computer
Efficient – optimal use of resources
Reliable – Do what is expected and handle exception
5. Which of the following best describe pseudo-code?
a. Low level programming language c. Actual executable code
b. Human readable algorithm representation d. Machine code
Explanation: It is human readable algorithm representation
6. Which of the following is incorrect?:
a) Algorithms can be represented as pseudo codes
b) Algorithms can be represented as syntax
c) Algorithms can be represented as programs
d) Algorithms can be represented as flowcharts
Explanation: Representation of algorithms:
-As programs
-As flowcharts
-As pseudo codes.
7. Who invented C++?
a) Dennis Ritchie
b) Ken Thompson
c) Brian Kernighan
d) Bjarne Stroustrup
Explanation: Bjarne Stroustrup is the original creator of C++ in 1979 at AT&T Bell Labs.
8. What is C++?
a) C++ is an object oriented programming language
b) C++ is a procedural programming language
c) C++ supports both procedural and object oriented programming language
d) C++ is a functional programming language
Explanation: C++ supports both procedural (step by step instruction) and object oriented
programming (using the concept of classes and objects).
9. Which of the following is the correct syntax of including a user defined header files
in C++?
a) #include [userdefined]
b) #include “userdefined”
c) #include <userdefined.h>
d) #include <userdefined>
Explanation: C++ uses double quotes to include a user-defined header file. The correct
syntax of including user-defined is #include “userdefinedname”.
10. Which of the following is used for comments in C++?
a) /* comment */
b) // comment */
c) // comment
d) both // comment or /* comment */
Explanation: Both the ways are used for commenting in C++ programming. // is used for
single line comments and /* … */ is used for multiple line comments.
11. Which of the following extension is used for user-defined header file in c++?
a) hg
b) cpp
c) h
d) hf
Explanation: .h extensions are used for user defined header files. To include a user defined
header file, one should use #include”name.h” i.e. it should be enclosed within double
quotes.
12. Which of the following is a correct identifier in C++?
a) VAR_1234
b) $var_name
c) 7VARNAME
d) 7var_name
Explanation: The rules for writing an identifier is as follows:
i) may contain lowercase/uppercase letters, digits or underscore(_) only
ii) should start with a non-digit character
iii) should not contain any special characters like @, $, etc.
13. Which of the following is not a type of Constructor in C++?
a) Default constructor
b) Parameterized constructor
c) Copy constructor
d) Friend constructor
Explanation: Friend function is not a constructor whereas others are a type of constructor
used for object initialization.
14. Which of the following approach is used by C++?
a) Left-right
b) Right-left
c) Bottom-up
d) Top-down
Explanation: C++ is an object-oriented language and OOL uses a bottom-up approach
to solve/view a problem.
15. What happens if the following C++ statement is compiled and executed?
int *ptr = NULL;
delete ptr;
a) The program is not semantically correct
b) The program is compiled and executed successfully
c) The program gives a compile-time error
d) The program compiled successfully but throws an error during run-time
Explanation: The above statement is syntactically and semantically correct as C++
allows the programmer to delete a NULL pointer, therefore, the program is compiled and
executed successfully.
16. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
char s1[6] = "Hello";
char s2[6] = "World";
char s3[12] = s1 + " " + s2;
cout<<s3;
return 0;
}
a) Hello
b) World
c) Error
d) Hello World
Answer: c
Explanation: There is no operation defined for the addition of character array in C++ hence
the compiler throws an error as it does not understood what to do about this expression.
17. What happens if the following program is executed in C and C++?
#include <stdio.h>
int main(void)
{
int new = 5;
printf("%d", new);
}
a) Error in C and successful execution in C++
b) Error in both C and C++
c) Error in C++ and successful execution in C
d) A successful run in both C and C++
Explanation: new is a keyword in C++, therefore, we cannot declare a variable with name
new but as there is no such keyword new in C, therefore, the program is compiled and
executed successfully in C.
18. Which of the following C++ code will give error on compilation?
================code 1=================
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
cout<<"Hello World";
return 0;
}
========================================
================code 2=================
#include <iostream>
int main(int argc, char const *argv[])
{
std::cout<<"Hello World";
return 0;
}
========================================
a) Code 1 only
b) Neither code 1 nor code 2
c) Both code 1 and code 2
d) Code 2 only
Explanation: Neither code 1 nor code 2 will give an error as both are syntactically correct as
in first code we have included namespace std and in second one we have used scope
resolution operator to resolve the conflict.
19. Which of the following type is provided by C++ but not C?
a) double
b) float
c) int
d) bool
Answer: d
Explanation: C++ provides the boolean type to handle true and false values whereas no
such type is provided in C.
20. What is the value of p in the following C++ code snippet?
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int p;
6. bool a = true;
7. bool b = false;
8. int x = 10;
9. int y = 5;
10. p = ((x | y) + (a + b));
11. cout << p;
12. return 0;
13. }
a) 12
b) 0
c) 2
d) 16
Explanation: | means bitwise OR operation so x | y (0101 | 1010) will be evaluated to 1111
which is integer 15 and as a is true and b is false so a+b(1 + 0) = 1. So final value of
expression in line #10 will be 15 + 1 = 16.
14. Which of the following correctly declares an array in C++?
a) array{10};
b) array array[10];
c) int array;
d) int array[10];
Explanation: Because array variable and values need to be declared after the datatype
only.
15. Which of the following symbol is used to declare the preprocessor directives in C++?
a) $
b) ^
c) #
d) *
Explanation: # symbol is used to declare the preprocessor directives.
16. What will be the output of the following C++ code?
1. #include <iostream>
2. using namespace std;
3. int main ()
4. {
5. int a, b, c;
6. a = 2;
7. b = 7;
8. c = (a > b) ? a : b;
9. cout << c;
10. return 0;
11. }
a) 12
b) 14
c) 6
d) 7
17. What will be the output of the following C++ code snippet?
1. #include <stdio.h>
2. #include<iostream>
3. using namespace std;
4. int main ()
5. {
6. int array[] = {0, 2, 4, 6, 7, 5, 3};
7. int n, result = 0;
8. for (n = 0; n < 8; n++)
9. {
10. result += array[n];
11. }
12. cout << result;
13. return 0;
14. }
a) 21 c) 26
b) 27 d) 25
Explanation: We are adding all the elements in the array and printing it. Total elements in
the array is 7, but our for loop will go beyond 7 and add a garbage value.