Skip to content
main-logo
  • +91 637-050-2482
  • santuitreturns@gmail.com
Menu
Menu
  • Home
  • Income Tax
    • Income From Salary
    • Profit or gain from Business/Profession.
    • Capital Gain
    • Income From Other Sources
    • 80C to 80U
    • TDS & TCS
    • ITR FORMS
  • International Taxation
    • Transfer Pricing
    • Non-Resident Taxation
    • Foreign Tax Credit (FTC)
    • Model Tax Convention
    • Base Erosion and Profit Shifting (BEPS)
  • GST
  • Accounting
  • MCQs
    • NEET
    • NEET QUIZ TEST
    • NEET PG MCQ’s
    • NEET PG QUIZ TEST
    • Civil Engineering
    • Mechanical Engineering MCQs
    • CHSL EXAM
      • Logical Reasoning
  • Others
    • Job Tips
  • CA Courses
    • CA Inter/IPCC

TOP 20+ MCQs on Stack using Array Data Structure with Answers

Posted on November 15, 2023

1. Which of the following real world scenarios would you associate with a stack data structure?

A. piling up of chairs one above the other
B. people standing in a line to be serviced at a counter
C. offer services based on the priority of the customer
D. tatkal Ticket Booking in IRCTC

View Answer

Answer: A

Explanation: 

Stack follows Last In First Out (LIFO) policy. Piling up of chairs one above the other is based on LIFO, people standing in a line is a queue and if the service is based on priority, then it can be associated with a priority queue. Tatkal Ticket Booking Follows First in First Out Policy. People who click the book now first will enter the booking page first.

2. What does the following function check for? (all necessary headers to be included and function is called from main)

#define MAX 10
 
typedef struct stack
{
    int top;
    int item[MAX];
}stack;
 
int function(stack *s)
{
    if(s->top == -1)
        return 1;
    else return 0;
}

A. full stack
B. invalid index
C. empty stack
D. infinite stack

View Answer

Answer: C

Explanation:

 An empty stack is represented with the top-of-the-stack(‘top’ in this case) to be equal to -1.

3. What does ‘stack underflow’ refer to?

A. accessing item from an undefined stack
B. adding items to a full stack
C. removing items from an empty stack
D. index out of bounds exception

View Answer

Answer: C

Explanation:

 Removing items from an empty stack is termed as stack underflow.

4. What is the output of the following program?

public class Stack
{
	protected static final int CAPACITY = 100;
	protected int size,top = -1;
	protected Object stk[];
 
	public Stack()
	{
		stk = new Object[CAPACITY];
	}
 
	public void push(Object item)
	{
		if(size_of_stack==size)
		{
			System.out.println("Stack overflow");
				return;
		}
		else
		{
			top++;
			stk[top]=item;
		}
	}
	public Object pop()
	{
		if(top<0)
		{
			return -999;
		}
		else
		{
			Object ele=stk[top];
			top--;
			size_of_stack--;
			return ele;
		}
	}
}
 
public class StackDemo
{
	public static void main(String args[])
	{
		Stack myStack = new Stack();
		myStack.push(10);
		Object element1 = myStack.pop();
		Object element2 = myStack.pop();
		System.out.println(element2);
	}
}

A. stack is full
B. 20
C. 0
D. -999

View Answer

Answer: D

Explanation:

 The first call to pop() returns 10, whereas the second call to pop() would result in stack underflow and the program returns -999.

5. What is the time complexity of pop() operation when the stack is implemented using an array?

A. O(1)
B. O(n)
C. O(logn)
D. O(nlogn)

View Answer

Answer: A

Explanation:

 pop() accesses only one end of the structure, and hence constant time.

6. Which of the following array position will be occupied by a new element being pushed for a stack of size N elements(capacity of stack > N)?

A. S[N-1]
B. S[N]
C. S[1]
D. S[0]

View Answer

Answer: B

Explanation:

 Elements are pushed at the end, hence N.

7. What happens when you pop from an empty stack while implementing using the Stack ADT in Java?

A. Undefined error
B. Compiler displays a warning
C. EmptyStackException is thrown
D. NoStackException is thrown

View Answer

Answer: C

Explanation:

The Stack ADT throws an EmptyStackException if the stack is empty and a pop() operation is tried on it.

8. What is the functionality of the following piece of Java code? Assume: ‘a’ is a non empty array of integers, the Stack class creates an array of specified size and provides a top pointer indicating TOS(top of stack), push and pop have normal meaning.
public void some_function(int[] A.
{
	Stack S=new Stack(a.length);
	int[] b=new int[a.length];
	for(int i=0;i<a.length;i++)
	{
		b[i]=(int)(S.pop());
	}
	System.out.println("output :");
	for(int i=0;i<b.length;i++)
	{
		System.out.println(b[i]);
	}

A. print alternate elements of array
B. duplicate the given array
C. parentheses matching
D. reverse the array

View Answer

Answer: D

Explanation:

 Every element from the given array ‘a’ is pushed into the stack, and then the elements are popped out into the array ‘b’. Stack is a LIFO structure, this results in reversing the given array.

9. Array implementation of Stack is not dynamic, which of the following statements supports this argument?

A. space allocation for array is fixed and cannot be changed during run-time
B. user unable to give the input for stack operations
C. a runtime exception halts execution
D. improper program compilation

View Answer

Answer: A

Explanation:

 You cannot modify the size of an array once the memory has been allocated, adding fewer elements than the array size would cause wastage of space, and adding more elements than the array size at run time would cause Stack Overflow.

10. Which of the following array element will return the top-of-the-stack-element for a stack of size N elements(capacity of stack > N)?

A. S[N-1]
B. S[N]
C. S[N-2]
D. S[N+1]

View Answer

Answer: A

Explanation:

 Array indexing start from 0, hence N-1 is the last index.

    You May Also Like...

  • 10+ TOP MCQs on C++ vs C
  • 10+ TOP C++ MCQs on Sizes
  • 10+ TOP C++ MCQs on Void
  • 10+ TOP C++ MCQs on Pointer to Void
  • 10+ TOP C++ MCQs on Operator Overloading – 2
  • 10+ TOP C++ MCQs on Increment and Decrement
  • 10+ TOP C++ MCQs on String Class
  • 10+ TOP C++ MCQs on Class Hierarchies and Abstract Classes

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Quick Links

  • Home
  • About Us
  • Privacy Policy
  • Terms of Use
  • Disclaimer
  • Contact Us

Categories

  • Income Tax
  • International Taxation
  • GST
  • MCQs
  • Others
  • CA Courses

Latest Posts

  • Five changes in ITR forms of FY 2024-25 (AY 2025-26)
  • Form 10-IEA: Option to Choose Old Tax Regime
  • What is Section 54EC of the Income Tax Act?
  • What is Section 54F of the Income Tax Act?
©2025 Online Solves. All rights Reserved | Developed by AlgoPage IT Solutions Pvt. Ltd.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT