Questions bank

Programming Interview Guide                      SOFTWARE ENGINEERING              NETWORKING

Programming Questions             DATABASE MANAGEMENT               DATA STRUCTURE

Software Engineering questions

1. Software is defined as ___________

a) set of programs, documentation & configuration of data

b) set of programs

c) documentation and configuration of data

d) None of the mentioned


Answer: a

Explanation: Software is a collection of programmes; it also includes documentation and data setup to enable the programmes to function. Microsoft windows, excel, word, powerpoint, etc. are a few examples of software.

2. What is Software Engineering?

a) Designing a software

b) Testing a software

c) Application of engineering principles to the design a software

d) None of the above


Answer: c

Explanation: Software engineering is the application of engineering principles to the design, development, and support of software and it helps to solve the challenges of low-quality software projects.

3. Who is the father of Software Engineering?

a) Margaret Hamilton

b) Watts S. Humphrey

c) Alan Turing

d) Boris Beizer


Answer: b

Explanation: Watts S. Humphrey created the Software Process Program at Carnegie Mellon University’s Institute (SEI) in the 1980s, and served as its director from 1986 through the early 1990s. This program was designed to help participants understand and manage the software developement process.

4. What are the features of Software Code?

a) Simplicity

b) Accessibility

c) Modularity

d) All of the above


Answer: c

Explanation: Software code should be written in a clear, succinct, and easy-to-understand way. Simplicity should be preserved in the program code’s organization, implementation, and design. These codes should be constructed in such a way that software components (such as files and functions) are readily available. The software may be broken down into numerous parts to make it easier to comprehend and troubleshoot.

5. ____________ is a software development activity that is not a part of software processes.

a) Validation

b) Specification

c) Development

d) Dependence


Answer: d

Explanation: A software dependency is an external independent library that can range in size from a single file to numerous files and directories arranged into packages to accomplish a specified purpose and is an attribute and not an engineering activity for process.

advertisement

6. Define Agile scrum methodology.

a) project management that emphasizes incremental progress

b) project management that emphasizes decremental progress

c) project management that emphasizes neutral progress

d) project management that emphasizes no progress


Answer: a

Explanation: Agile scrum methodology is a style of project management that emphasizes incremental progress. Each iteration is divided into two to four-week sprints, with the goal of completing the most important features first and delivering a possibly deliverable product at the end of each sprint.

7. CASE stands for

a) Computer-Aided Software Engineering

b) Control Aided Science and Engineering

c) Cost Aided System Experiments

d) None of the mentioned


Answer: a

Explanation: The CASE tool’s purpose is to make the work of software development and maintenance easier and more reliable.

8. ________ is defined as the process of generating analysis and designing documents?

a) Re-engineering

b) Reverse engineering

c) Software re-engineering

d) Science and engineering


Answer: b

Explanation: The method of reverse engineering is used to uncover difficult, unknown, and hidden information about a software system.

9. The activity that distributes estimated effort across the planned project duration by allocating the effort to specific software developing tasks is ____________

a) Project scheduling

b) Detailed schedule

c) Macroscopic schedule

d) None of the mentioned


Answer: a

Explanation: Software project scheduling is the process of allocating anticipated effort to specific software developing activities and distributing it across the project’s intended length. A macroscopic schedule is created in the early phases of project planning.

10. What is a Functional Requirement?

a) specifies the tasks the program must complete

b) specifies the tasks the program should not complete

c) specifies the tasks the program must not work

d) All of the mentioned


Answer: a

Explanation: A functional requirement is a specification that describes a system or one of its components. It specifies the tasks the program must complete. A function is made up of three parts: inputs, behavior, and outputs.

11. Why do bugs and failures occur in software?

a) Because of Developers

b) Because of companies

c) Because of both companies and Developers

d) None of the mentioned


Answer: c

Explanation: Software businesses are in charge of establishing policies and creating a working environment for software development, therefore they are a component of the software development process. Bugs from developers are nothing new.

12. Attributes of good software is ____________

a) Development

b) Maintainability & functionality

c) Functionality

d) Maintainability


Answer: b

Explanation: Good software should provide the functionality and maintainability that are necessary. Software development is a must, not an option. Along with this software also additional attributes like usability, efficiency, reliability, accuracy, robustness, integrity, etc.

13. The Cleanroom philosophy was proposed by _________

a) Linger

b) Mills

c) Dyer

d) All of the Mentioned


Answer: d

Explanation: Mills, Dyer, and Linger initially suggested the Cleanroom concept in the 1980s. The main goal of the philosophy of cleanroom philosophy is to develop software with zero defects.

14. What does SDLC stands for?

a) System Design Life Cycle

b) Software Design Life Cycle

c) Software Development Life Cycle

d) System Development Life cycle


Answer: c

Explanation: The Software Development Life Cycle (SDLC) is a method for designing, developing, and testing high-quality software. The software developed to meet or exceed customer expectations must have an SDLC designed to complete the software on time and on budget.

15. Who proposed the spiral model?

a) Barry Boehm

b) Pressman

c) Royce

d) IBM


Answer: a

Explanation: The spiral model by Boehm, is a software process model that combines prototyping’s iterative characteristic with the linear sequential model’s regulated and systematic elements. It implements the capability of quick production of new software versions.

16. ______________ is not among the eight principles followed by the Software Code of Ethics and Professional Practice.

a) PRODUCT

b) ENVIRONMENT

c) PUBLIC

d) PROFESSION


Answer: b

Explanation: The rest are software ethical provisions; the environment does not focus on individual clauses or their importance in relation to the topic. The eight principles that should be followed by the Software code is:

1. PUBLIC

2. CLIENT AND EMPLOYER

3. PRODUCT

4. JUDGMENT

5. MANAGEMENT

6. PROFESSION

7. COLLEAGUES

8. SELF

17. Which of the following are CASE tools?

a) Central Repository

b) Integrated Case Tools

c) Upper Case Tools

d) All of the mentioned


Answer: d

Explanation: CASE tools can be divided into Central Repository, Integrated Case Tools, Upper Case Tools, and Lower Case Tools based on their use at a particular SDLC stage.

18. __________________ suits the Manifesto for Agile Software Development.

a) Customer collaboration

b) Individuals and interactions

c) Working software

d) All of the mentioned


Answer: d

Explanation: None.

19. Software patch is defined as ______________

a) Daily or routine Fix

b) Required or Critical Fix

c) Emergency Fix

d) None of the mentioned


Answer: c

Explanation: When a vulnerability is discovered, a software patch is applied to the outdated version as an emergency repair. To repair a vulnerability or flaw discovered after an application or software has been released is referred to as software patching.

20. __________ software development team has no permanent leader.

a) Controlled Centralized (CC)

b) Controlled decentralized (CD)

c) Democratic decentralized (DD)

d) None of the mentioned


Answer: c

Explanation: Team members Communicate among themselves horizontally. There is no permanent leader in the team and a team of software engineers coordinates among themselves temporarily to perform the task.

21. Regardless of application area, project size, or complexity, software development work may be divided into three generic phases: the__________ phase, which focuses on what, the_________ phase, which focuses on how, and the_________ phase, which focuses on change.

i. support

ii. development

iii. definition

a) iii, ii, i

b) iii, i, ii

c) i, ii, iii

d) ii, i, iii


Answer: a

Explanation: Irrespective of the application area, project size, or complexity, software development work may be divided into three generic phases: the definition phase, which focuses on what, the development phase, which focuses on how, and the support phase, which focuses on change.

22. _________ is not a fundamental activity for software processes in software development.

a) Evolution

b) Design and implementation

c) Validation

d) Verification


Answer: d

Explanation: Implementation and testing activities account for software verification. Software Verification is a process that ensures that the software developed is accurate and meets the user’s expectations.

23. What are agile manifesto principles?

a) Customer satisfaction

b) Face-to-face communication within a development team

c) Changes in requirements are welcome

d) All of the mentioned


Answer: d

Explanation: Principles of the agile manifesto are:

i) Customer satisfaction is a priority.

ii) Changes in requirements are welcome, if they occur late in the development process.

iii) Deliver working software on a regular basis.

iv) Business people and developers must connect on a daily basis through the project.

v) Support people who are interested and passionate about developing.

vi) Face-to-face communication within a development team.

vii) Working software indicates progress.

viii) Sustainable development is aided by agile processes.

ix) A constant focus on technical excellence and smart design improve agility.

x) Simplicity, or the art of minimizing the amount of effort that isn’t done, is critical.

xi) Self-organizing teams

xii) The team reflects on how to become more effective at regular intervals, then selects its behavior accordingly.

24. Faster delivery is possible with CBSE.

a) False

b) True


Answer: b

Explanation: They build more dependable systems at a faster rate because they use previously validated components. The software developed by CBSE uses reusable components.

25. Who proposed Function Points?

a) Albrecht

b) Jacobson

c) Boehm

d) Booch


Answer: a

Explanation: Since Albrecht presented functional points in 1979, hundreds of books and articles have been produced on the subject.

26. _________ is a software development life cycle model that is chosen if the development team has less experience on similar projects.

a) Iterative Enhancement Model

b) RAD

c) Spiral

d) Waterfall


Answer: c

Explanation: For many applications, relying on risk assessment/analysis gives more freedom than is necessary, overcoming the requirements of less experienced developers.

27. Agile Software Development is based on which of the following type?

a) Iterative Development

b) Incremental Development

c) Both Incremental and Iterative Development

d) Linear Development


Answer: c

Explanation: The software is built in increments, with the client stating the criteria to be included in each increment, and the top goal is to please the customer by delivering valuable software early and frequently. They’re iterative because they work on one iteration before moving on to the next.

28. _______________________ is a software developing team has a defined leader who coordinates specific tasks and secondary leaders that have responsibility for sub tasks.

a) Democratic decentralized (DD)

b) Controlled centralized (CC)

c) Controlled decentralized (CD)

d) None of the mentioned


Answer: c

Explanation: Problem-solving is still a group activity, but the team leader divides the execution of solutions into subgroups and it is known as a Controlled decentralized team. In Democratic decentralized, there is no permanent leader in the team and a team of software developers coordinates among themselves temporarily to perform the task.

29. 4GT Model is a set of __________________

a) Programs

b) CASE Tools

c) Software tools

d) None of the mentioned


Answer: c

Explanation: 4GT is a collection of software tools that allow a software developer to describe high-level features and have source code created automatically based on those requirements.

30. Engineers developing software should not

a) be dependent on their colleagues

b) maintain integrity and independence in their professional judgment

c) not knowingly accept work that is outside your competence

d) not use your technical skills to misuse other people’s computers


Answer: a

Explanation:None.

31. __________ is not suitable for accommodating any change?

a) RAD Model

b) Waterfall Model

c) Build & Fix Model

d) Prototyping Model


Answer: b

Explanation: Real-world projects seldom follow the Waterfall Model’s proposed sequential sequence. A Sequential model is an example of a waterfall model. The software development activity is split into several phases in this paradigm, with each phase consisting of a sequence of activities and having different goals.

32. The model which has a major disadvantage in terms of the coding phase of a software life cycle model is ________

a) Rad Model

b) Spiral Model

c) 4GT Model

d) Waterfall Model


Answer: c

Explanation: Since the coding phase is eliminated in 4GT Model, more expertise is required for analysis, design and testing activities.

33. Adaptive Software Development(ASD) has which of the following three framework activities?

a) speculation, collaboration, learning

b) analysis, design, coding

c) requirements gathering, adaptive cycle planning, iterative development

d) all of the mentioned


Answer: a

Explanation: None.

34. Which of the following is not a project factor that should be considered when planning the structure of software developing teams?

a) The rigidity of the delivery date

b) The degree of sociability required for the project

c) High frustration caused by personal, business, or technological factors that causes friction among team members

d) The difficulty of the problem to be solved


Answer: b

Explanation: Development is irrelevant to the social quotient.

35. What is the full form of the “COCOMO” model?

a) Cost Constructive Estimation Model

b) Constructive Cost Estimation Model

c) Constructive Case Estimation Model

d) Constructive Cost Estimating Model


Answer: b

Explanation: The Cocomo (Constructive Cost Model) regression model is based on the number of lines of code. It is a procedural cost estimate model that is frequently used as a method of accurately estimating size, effort, cost, duration, and quality for a project completion.

36. Which one of the following is not a software process quality?

a) Visibility

b) Timeliness

c) Productivity

d) Portability


Answer: d

Explanation: Portability is a software product quality which means software can run on different hardware platforms or environments.

37. Cleanroom software development process complies with the operational analysis principles by using a method called known as

a) referential transparency

b) degenerative error correction

c) box structure specification

d) none of the mentioned


Answer: c

Explanation: Box structures are descriptions of functions that exhibit properties essential for effective system specification and design.

38. What is system software?

a) computer program

b) Testing

c) AI

d) IOT


Answer: a

Explanation: System software is a sort of computer program that manages the hardware and applications on a computer. They are of three types: This is the operating system. This is a language processor. Software that is useful.

39. Quality Management is known as _______

a) SQI

b) SQA

c) SQM

d) SQA and SQM


Answer: b

Explanation: Software quality assurance (SQA) is another name for quality management, which is an umbrella activity that is used throughout the software development process.

40. _____________ is the definition of objects in the database that leads directly to a standard approach for the creation of software documentation.

a) Data/data integration

b) Information sharing

c) Document standardization

d) Data integrity


Answer: c

Explanation: In a software project, documentation standards are critical since papers are the only concrete means to describe the program and the development process. Standardized papers should be easy to read and comprehend since they have a uniform look, structure, and quality.

41. ______________ is an indirect measure of software development process.

a) Cost

b) Effort Applied

c) Efficiency

d) All of the mentioned


Answer: c

Explanation: Efficiency is an indirect measure. Indirect measures also include products like maintainability, quality, functionality, complexity, reliability, and many more.

42. According to an IBM research, “31% of projects are abandoned before they are completed, 53% exceed their cost projections by an average of 189 percent, and 94 projects are restarted for every 100 projects.” What is the significance of these figures?

a) Lack of software ethics and understanding

b) Management issues in the company

c) Lack of adequate training

d) All of the mentioned


Answer: c

Explanation: Lack of software ethics and knowledge, as well as corporate management difficulties, are all aspects of Software Development, therefore this is a possibility. Both are due to a lack of sufficient training.

43. Which of the following document contains the user system requirements?

a) SRD

b) DDD

c) SDD

d) SRS


Answer: d

Explanation: A software requirements specification (SRS) is a detailed explanation of how a system should behave before it is built. It may also include a collection of use cases that explain how users will interact with the programme.

44. _____________ specification is also known as SRS document.

a) white-box

b) grey-box

c) black-box

d) none of the mentioned


Answer: c

Explanation: The system is regarded as a black box, with no knowledge of its underlying workings, and just its observable exterior (input/output) behavior described.

45. Which of the following is not a part of Software evolution?

a) Re-engineering activities

b) Maintenance activities

c) Development activities

d) Negotiating with client


Answer: d

Explanation: The study and management of the process of making changes to software through time is referred to as software evolution. As a result, the remaining three alternatives are available.

46. ___________ is a Strategy to achieve Software diversity.

a) Explicit specification of different algorithms

b) Different programming languages

c) Different design methods and tools

d) All of the mentioned


Answer: d

Explanation: Diversity refers to the ability to deliver the same functionality in a variety of ways so that essential components of a dependable system do not fail in the same way. Because we all have varied life experiences, backgrounds, and expertise, adding variety to the problem-solving process is essential because it allows us to come up with new ideas and methods.

47. In which step of SDLC actual programming of software code is done?

a) Development and Documentation

b) Maintenance and Evaluation

c) Design

d) Analysis


Answer: a

Explanation: The documentation explains the functions of the final product. The developer must discover adequate knowledge in the technical documentation to begin coding.

48. Software Debugging is known as _________________

a) identifying the task to be computerized

b) creating program code

c) creating the algorithm

d) finding and correcting errors in the program code


Answer: d

Explanation: Software Debugging is the systematic process of identifying and decreasing the number of bugs or faults in a computer program or a piece of electrical gear so that it behaves as intended.

49. The word which describes the importance of software design is?

a) Complexity

b) Quality

c) Efficiency

d) Accuracy


Answer: b

Explanation: The degree to which software complies with or adheres to a particular design based on functional requirements or specifications is referred to as functional quality.

50. The incorrect activity among the following for the configuration management of a software system is ________

a) Version management

b) System management

c) Change management

d) Internship management


Answer: d

Explanation: The policies and methods for configuration management describe how to track and process proposed system changes, as well as how to select which system components to modify, how to manage various versions of the system and its components, and how to disseminate changes to customers.

Networking and communication

Data structure and algorithm

Coding Problems from Programming Job interviews

Without wasting any more of your time, here is my list of 100 frequently asked coding problems from programming job interviews. In order to get most of this list, I suggest actually solving the problem.

Do it yourself, no matter whether you are stuck because that’s the only way to learn. After solving a couple of problems you will gain confidence.

I also suggest you look at the solution when you are stuck or after you have solved the problem, this way you learn to compare different solutions and how to approach a problem from a different angle.


computer programming


1. Who invented C++?

a) Dennis Ritchie

b) Ken Thompson

c) Brian Kernighan

d) Bjarne Stroustrup

Answer: d

Explanation: Bjarne Stroustrup is the original creator of C++ in 1979 at AT&T Bell Labs.

2. 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

Answer: c

Explanation: C++ supports both procedural(step by step instruction) and object oriented programming (using the concept of classes and objects).

3. 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>


Answer: b

Explanation: C++ uses double quotes to include a user-defined header file. The correct syntax of including user-defined is #include “userdefinedname”.

4. Which of the following is used for comments in C++?

a) /* comment */

b) // comment */

c) // comment

d) both // comment or /* comment */



Answer: d

Explanation: Both the ways are used for commenting in C++ programming. // is used for single line comments and /* … */ is used for multiple line comments.

5. Which of the following user-defined header file extension used in c++?

a) hg

b) cpp

c) h

d) hf



Answer: c

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. enclosed within double quotes.

advertisement

6. Which of the following is a correct identifier in C++?

a) VAR_1234

b) $var_name

c) 7VARNAME

d) 7var_name



Answer: a

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.

7. Which of the following is not a type of Constructor in C++?

a) Default constructor

b) Parameterized constructor

c) Copy constructor

d) Friend constructor



Answer: d

Explanation: Friend function is not a constructor whereas others are a type of constructor used for object initialization.

8. Which of the following approach is used by C++?

a) Left-right

b) Right-left

c) Bottom-up

d) Top-down



Answer: c

Explanation: C++ is an object-oriented language and OOL uses a bottom-up approach to solve/view a problem.

9. What is virtual inheritance in C++?

a) C++ technique to enhance multiple inheritance

b) C++ technique to ensure that a private member of the base class can be accessed somehow

c) C++ technique to avoid multiple inheritances of classes

d) C++ technique to avoid multiple copies of the base class into children/derived class



Answer: d

Explanation: Virtual inheritance is a C++ technique with which it ensures that a derived class contains only one copy of the base class’s variables. Refer Wikipedia for more info.

10. 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



Answer: b

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.

11. 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.

12. What is the difference between delete and delete[] in C++?

a) delete is syntactically correct but delete[] is wrong and hence will give an error if used in any case

b) delete is used to delete normal objects whereas delete[] is used to pointer objects

c) delete is a keyword whereas delete[] is an identifier

d) delete is used to delete single object whereas delete[] is used to multiple(array/pointer of) objects



Answer: d

Explanation: delete is used to delete a single object initiated using new keyword whereas delete[] is used to delete a group of objects initiated with the new operator.

13. 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++



Answer: 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.

14. What happens if the following program is executed in C and C++?


#include <stdio.h> 

void func(void)

{

printf("Hello");

}

void main() 

func();

func(2);

}

a) Outputs Hello twice in both C and C++

b) Error in C and successful execution in C++

c) Error in C++ and successful execution in C

d) Error in both C and C++



Answer: d

Explanation: As the func(void) needs no argument during its call, hence when we are calling func(2) with 2 as passed as a parameter then this statement gives the error in both C++ and C compiler.

15. Which of the following is correct about this pointer in C++?

a) this pointer is passed as a hidden argument in all static variables of a class

b) this pointer is passed as a hidden argument in all the functions of a class

c) this pointer is passed as a hidden argument in all non-static functions of a class

d) this pointer is passed as a hidden argument in all static functions of a class



Answer: c

Explanation: As static functions are a type of global function for a class so all the object shares the common instance of that static function whereas all the objects have there own instance for non-static functions and hence they are passed as a hidden argument in all the non-static members but not in static members.

16. What will be the output of the following C++ code?


    #include <iostream>

    #include <string>

    #include <algorithm>

    using namespace std;

    int main() 

    {

        string s = "spaces in text";

        s.erase(remove(s.begin(), s.end(), ' ' ), s.end() ) ;

        cout << s << endl;

    }

a) spacesintext

b) spaces in text

c) spaces

d) spaces in



Answer: a

Explanation: In this program, We formed a algorithm to remove spaces in the string.

Output:

$ g++ dan.cpp

$ a.out

spacesintext

17. 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



Answer: b

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.

18. 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.

19. What is the value of p in the following C++ code snippet?


    #include <iostream>

    using namespace std;

    int main()

    {

        int p;

        bool a = true;

        bool b = false;

        int x = 10;

        int y = 5;

        p = ((x | y) + (a + b));

        cout << p;

        return 0;

    }

a) 12

b) 0

c) 2

d) 16



Answer: d

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.

20. By default, all the files in C++ are opened in _________ mode.

a) Binary

b) VTC

c) Text

d) ISCII



Answer: c

Explanation: By default, all the files in C++ are opened in text mode. They read the file as normal text.

21. What will be the output of the following C++ function?


    int main()

    {

        register int i = 1;

        int *ptr = &i;

        cout << *ptr;

return 0;

    }

a) Runtime error may be possible

b) Compiler error may be possible

c) 1

d) 0



Answer: b

Explanation: Using & on a register variable may be invalid, since the compiler may store the variable in a register, and finding the address of it is illegal.

22. Which of the following correctly declares an array in C++?

a) array{10};

b) array array[10];

c) int array;

d) int array[10];



Answer: d

Explanation: Because array variable and values need to be declared after the datatype only.

23. What is the size of wchar_t in C++?

a) Based on the number of bits in the system

b) 2 or 4

c) 4

d) 2



Answer: a

Explanation: Compiler wants to make CPU as more efficient in accessing the next value.

24. What will be the output of the following C++ code?


#include<iostream>

using namespace std;

int main ()

{

   int cin;

   cin >> cin;

   cout << "cin: " << cin;

   return 0;

}

a) Segmentation fault

b) Nothing is printed

c) Error

d) cin: garbage value



Answer: d

Explanation: cin is a variable hence overrides the cin object. cin >> cin has no meaning so no error.

25. What is the use of the indentation in c++?

a) r distinguishes between comments and inner data

b) distinguishes between comments and outer data

c) distinguishes between comments and code

d) r distinguishes between comments and outer data



Answer: c

Explanation: To distinguish between different parts of the program like comments, codes, etc.

26. Which is more effective while calling the C++ functions?

a) call by object

b) call by pointer

c) call by value

d) call by reference



Answer: d

Explanation: In the call by reference, it will just passes the reference of the memory addresses of passed values rather than copying the value to new memories which reduces the overall time and memory use.

27. What will be the output of the following C++ program?


#include <iostream> 

#include <string>

#include <cstring>

using namespace std; 

int main(int argc, char const *argv[])

{

const char *a = "Hello\0World";

cout<<a;

return 0;

}

a) Hello

b) World

c) Error

d) Hello World



Answer: a

Explanation: char* are terminated by a ‘\0’ character so the string “Hello\0World” will be cut down to “Hello”.

28. Which of the following is used to terminate the function declaration in C++?

a) ;

b) ]

c) )

d) :



Answer: a

Explanation: ; semicolon is used to terminate a function declaration statement in C++.

29. What will be the output of the following C++ code?


    #include <iostream>

    using namespace std;

    int main()

    {

        char c = 74;

        cout << c;

        return 0;

    }

a) I

b) J

c) A

d) N



Answer: b

Explanation: The literal value for 74 is J. So it will be printing J.

30. What will be the output of the following C++ program?


    #include <iomanip>

    #include <iostream>

    using namespace std;

    int main()

    {

        cout << setprecision(17);

        double d = 0.1;

        cout << d << endl;

        return 0;

    }

a) compile time error

b) 0.100001

c) 0.11

d) 0.10000000000000001



Answer: d

Explanation: The double had to truncate the approximation due to its limited memory, which resulted in a number that is not exactly 0.1.

Output:

$ g++ float2.out

$ a.out

0.10000000000000001

31. Which keyword is used to define the macros in c++?

a) #macro

b) #define

c) macro

d) define



Answer: b

Explanation: #define is the keyword that is used to define the macros in c++.

32. What is the correct syntax of accessing a static member of a class in C++?


---------------------------

Example class:

class A

{

public:

static int value;

}

---------------------------

a) A->value

b) A^value

c) A.value

d) A::value



Answer: d

Explanation: Scope resolution operator(::) is used to access a static member of a class.

33. The C++ code which causes abnormal termination/behaviour of a program should be written under _________ block.

a) catch

b) throw

c) try

d) finally



Answer: c

Explanation: Code that leads to the abnormal termination of the program should be written under the try block.

34. What is Inheritance in C++?

a) Deriving new classes from existing classes

b) Overloading of classes

c) Classes with same names

d) Wrapping of data into a single class



Answer: a

Explanation: Inheritance is the concept of OOPs in which new classes are derived from existing classes in order to reuse the properties of classes defined earlier.

35. What will be the output of the following C++ code?


    #include <iostream>

    using namespace std;

    int main()

    {

        int a = 5;

        float b;

        cout << sizeof(++a + b);

        cout << a;

        return 0;

    }

a) 2 5

b) 4 5

c) 4 6

d) 2 6



Answer: b

Explanation: The a as a integer will be converted to float while calculating the size. The value of any variable doesn’t modify inside sizeof operator. Hence value of variable a will remain 5.

Output:

$ g++ size3.cpp

$ a.out

4 5

36. Which of the following symbol is used to declare the preprocessor directives in C++?

a) $

b) ^

c) #

d) *



Answer: c

Explanation: # symbol is used to declare the preprocessor directives.

37. What will be the output of the following C++ program?


#include<iostream>

using namespace std;

int main()

{

int a = 5;

auto check = [=]() 

        {

a = 10;

};

check();

cout<<"Value of a: "<<a<<endl;

return 0;

}

a) Segmentation fault

b) Value of a: 5

c) Value of a: 10

d) Error



Answer: d

Explanation: As this lambda expression is capturing the extrenal variable by value therefore the value of a cannot be changes inside the lambda expression hence the program gives error.

38. What will be the output of the following C++ code?


#include <iostream>

using namespace std;

void square (int *x, int *y)

{

*x = (*x) * --(*y);

}

int main ( )

{

int number = 30;

square(&number, &number);

cout << number;

return 0;

}

a) 30

b) Error

c) Segmentation fault

d) 870



Answer: d

Explanation: As we are passing value by reference therefore the change in the value is reflected back to the passed variable number hence value of number is changed to 870.

39. What is meant by a polymorphism in C++?

a) class having only single form

b) class having four forms

c) class having many forms

d) class having two forms



Answer: c

Explanation: Polymorphism is literally meant class having many forms.

40. What will be the output of the following C++ program?


#include <iostream>

#include <string>

using namespace std;

int main ()

{

  std::string str ("Sanfoundry.");

  str.back() = '!';

  std::cout << str << endl;

  return 0;

}

a) Sanfoundry!

b) Sanfoundry!.

c) Sanfoundry.

d) Sanfoundry.!



Answer: a

Explanation: back() function modifies the last character of the string with the character provided.

41. Pick the incorrect statement about inline functions in C++?

a) Saves overhead of a return call from a function

b) They are generally very large and complicated function

c) These functions are inserted/substituted at the point of call

d) They reduce function call overheads



Answer: b

Explanation: Inline are functions that are expanded when it is called. The whole code of the inline function gets inserted/substituted at the point of call. In this, they help in reducing the function call overheads. Also they save overhead of a return call from a function. Inline functions are generally kept small.

42. What will be the output of the following C++ program?


    #include <iostream>

    using namespace std;

    int main()

    {

        int n = 5;

        void *p = &n;

        int *pi = static_cast<int*>(p);

        cout << *pi << endl;

        return 0;

    }

a) 5

b) 6

c) compile time error

d) runtime error



Answer: a

Explanation: We just casted this from void to int, so it prints 5

Output:

$ g++ poi1.cpp

$ a.out

5

43. What is abstract class in C++?

a) Any Class in C++ is an abstract class

b) Class from which any class is derived

c) Class specifically used as a base class with atleast one virtual functions

d) Class specifically used as a base class with atleast one pure virtual functions



Answer: d

Explanation: An abstract class is defined as a class which is specifically used as a base class. An abstract class should have atleast one pure virtual function.

44. Which of the following constructors are provided by the C++ compiler if not defined in a class?

a) Copy constructor

b) Default constructor

c) Assignment constructor

d) All of the mentioned



Answer: d

Explanation: If a programmer does not define the above constructors in a class the C++ compiler by default provides these constructors to avoid error on basic operations.

45. What will be the output of the following C++ program?


#include <iostream>

using namespace std; 

int main()

{

    try

    {

        try

        {

            throw 20;

        }

        catch (int n)

        {

            cout << "Inner Catch\n";

            throw;

        }

    }

    catch (int x)

    {

        cout << "Outer Catch\n";

    }

    return 0;

}

a) Outer Catch

b)


Inner Catch

Outer Catch

c) Error

d) Inner Catch



Answer: b

Explanation: The exception thrown by the inner try catch block is caught by the inner block hence “Inner Catch” is printed but as inner catch block again throws an exception further therefore the exception is thrown further which is caught by the outer catch block hence “Outer Catch” is also printed.

46. Which concept allows you to reuse the written code in C++?

a) Inheritance

b) Polymorphism

c) Abstraction

d) Encapsulation



Answer: a

Explanation: Inheritance allows you to reuse your already written code by inheriting the properties of written code into other parts of the code, hence allowing you to reuse the already written code.

47. What will be the output of the following C++ code snippet?


    #include <iostream>

    using namespace std;

    int operate (int a, int b)

    {

        return (a * b);

    }

    float operate (float a, float b)

    {

        return (a / b);

    }

    int main()

    {

        int x = 5, y = 2;

        float n = 5.0, m = 2.0;

        cout << operate(x, y) <<"\t";

        cout << operate (n, m);

        return 0;

    }

a) 10.0 5

b) 10 2.5

c) 10.0 5.0

d) 5.0 2.5



Answer: b

Explanation: In this program, we are divide and multiply the values.

Output:

$ g++ over3.cpp

$ a.out

10 2.5

48. How structures and classes in C++ differ?

a) Structures by default hide every member whereas classes do not

b) In Structures, members are public by default whereas, in Classes, they are private by default

c) Structures cannot have private members whereas classes can have

d) In Structures, members are private by default whereas, in Classes, they are public by default



Answer: b

Explanation: Structure members are public by default whereas, class members are private by default. Both of them can have private and public members.

49. 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;

        return 0;

    }

a) 12

b) 14

c) 6

d) 7



Answer: d

Explanation: We are using the ternary operator to evaluate this expression. It will return first option, if first condition is true otherwise it will return second

Output:

$ g++ ess1.cpp

$ a.out

7

50. What is the benefit of c++ input and output over c input and output?

a) Both Type safety & Exception

b) Sequence container

c) Exception

d) Type safety



Answer: d

Explanation: C++ input and output are type safety that means we don’t need to specify the type of variable we are printing.

eg:

in C we need to specify %d showing that an integer will be printed, whereas in C++ we just cout the variable.

printf(“%d”, a);

cout<<a;

51. What will be the output of the following C++ code snippet?


    #include <stdio.h>

    #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) 21

b) 27

c) 26

d) 25



Answer: b

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.

52. What will be the output of the following C++ program?


    #include <iostream>

    #include <string>

    using namespace std;

    int main ()

    {

        string str ("Sanfoundry");

        for (size_t i = 0; i < str.length();)

        {

            cout << str.at(i-1);

        }

        return 0;

    }

a) runtime error

b) Sanfo

c) S

d) Sanfoundry

Answer: a

Explanation: This program will terminate because the cout element is out of range.

53. What will be the output of the following C++ program?

#include <iostream>

using namespace std;

class A{

public:

A(){

cout<<"Constructor called\n";

  }

~A(){

cout<<"Destructor called\n";

    } 

};

int main(int argc, char const *argv[])

{

A *a = new A[5];

delete[] a;

return 0;

}

a) Segmentation fault

b) “Constructor called” five times and then “Destructor called” five times

c) “Constructor called” five times and then “Destructor called” once

d) Error

Answer: b

Explanation: In the above program we have first initiated five-pointer variables using new keyword hence fives time constructor will be called after that as we using delete[] (used for deleting multiple objects) to delete variables hence all the five objects created will be destroyed and hence five times destructor will be called.