You are on page 1of 80

SONATA SOFTWARE COMPANY

SPECIFIC MCQS
• If call to library function - int no=strcmp(src,dest),
then value of "no" will be negative when
a) dest > src
b) src>dest
c) there is an error

d) both are same


• Find the output of the following code
#include <iostream>
using namespace std;
int main()
{
char *p;
char Str[] = "LALITHA";
p = Str;
p += 5;
cout << p;
return 0;
}
• a) HA b) LITHA c) ERROR d) LALITHA
• What is the worst case time complexity of merge
sort performed in a linked list?

a) O(n²)

b) O(n³)

c) O(nLogn)

d) O(Logn)
• When rear! = Max-1 in a queue, you can perform
__________ operation.

a) insertion

b) deletion

c) queue is full

d) queue is empty
• Consider a circular queue, where FRONT=MAX-1
and then a dequeue operation has been performed.

What is the current status of FRONT?

a) 0

b) -1

c) 1

d) 2
• What happens to the stack pointer when you pop
an element from a bottom-up stack?

a) Decremented by 1

b) incremented by 1

c) Decremented by 2

d) incremented by 2
• The expression "a=a%2" can also be expressed as

a) a=%2

b) a%=2
c) a=2%a

d) a%2
• Find the output of the following code 
#include <iostream>
using namespace std;
int main()
{
int y[] = {3, 00, 6, 4, 56};
int *p = (y + 4);
cout << *p;
return 0;
}
• a) 56 b) 0 c) 3, 00, 6, 4, 56 d) 3006456
• When both the strings are same strcmp, then the
library function will return

a) some positive value

b) error

c) zero

d) some negative value


• Which of the following library functions can be used
to identify the length of the given string/character
array?
a) strlen()

b) stringlen()

c) length()
d) strlength()
• What is the output of the following code?
int sum = 0;
int[][] table = {{3,4,5,6},{7,8,9,10}};
for(int x[] : table)
{
for(int y : x)
{
sum += y;
}
}
System.out.println(sum);
• a) 25 b) 52 c) 8 d) Compilation error
• Which of the following is the correct statement
about final classes in Java?

a) Final class cannot have public methods

b) Object of final classes cannot be created

c) Final classes cannot be inherited

d) Final class methods cannot return any value


• Can a constructor call another constructor in Java?

a) No, Java does not allow this

b) Yes, a constructor can call another constructor of


same class using this keyword

c) Yes, but only abstract class constructor can call


another constructor
d) Yes, but only final class constructor can call another
constructor
• Which of the following statements is correct?

1. Super keyword is used to call the parentclass


constructor.

2. Super keyword is used to access parent class method


in case of method overriding.

3. Super keyword is used to call the parent class


variable.
• a) statement 1 and 3 b) statement 2 and 3

• c) statement 1 and 2 d) statement 1,2 and 3


• What is the output of the following c program?
#include <stdio.h>
void display();
int main()
{
display();
display();
}
void display()
{
static int c = 0;
printf("%d ",c);
c += 10;
}
• a) 1 11 b) 0 10 c) 1 10 d) 2 10
• What will be the output of the following Java line?

int x=10;

if (x>11);
System.out.println("Hello"+x);

a) No output

b) Hello10

c) Compilation error

d) Hello11
• Which of the following are valid operations?

String s1=new String("Hi")

String s2=new String("Java");


String s3=new String();

a) s3=s1*s2

b) s3 = s1-s2

c) s3= s1+s2

d) s3 = s1&s3;
• If boolean expression in the if block evaluates to false,
then which statement set will be executed?
if (booleanExpression)
{
statementSet 1
}
else
{
statementSet 2
}
statementSet 3
• a) statementset1 b) statementset2 c) ststementset3
d) statementset 2 and statementset 3
• What should be the missing line to get the output 100? 
public class Example
{
public static void main(String args[])
{
int x = 0;
//__________
do
{
}
while(x++ < y);
System.out.println(x);
}
}
• a) int x=99; b) int x=100; c) int y=99; d) int y=100;
• Create a stack S of size 4, perform the following
operations and find the end result.
PUSH(S, A)
PUSH(S, B)
PUSH(S, C)
POP(S)
PUSH(S, D)
PUSH(S, E)
• a) Top = E b) Stack overflow c) Stack underflow
• d) TOP = D
• Which compound statement in a looping statement
is correct?

a) c=a+b

b) c=+b

c) c+=b

d) c=a-b
• EOL in the programming language indicates

a) End of line

b) End of language
c) Everything on line

d) End of life
• A __________ statement consists of a sequence of
two or more consecutive statements enclosed in
braces ({and}).
a) expression

b) compound

c) control
d) equation
• Complete the below given statement.

goto statements __________

a) are used to transfer control to the labelled


statements

b) goes to next statements

c) goes to the controlling statements

d) comes along with continue statement


• What will be the output of the following program?

main()

printf(“\nH\re\rll\ro”);

a) hello

b) o

c) Error

d) ol
• What will be the output of the following program? 
main()
{
static int i=100;
abc();
}
Void abc()
{
printf(“%d”,i);
}
• a) 100 b) 0 c) Error d) warning
• How to Pass a String to a Function?

a) void display(char s[])

b) void display
c) (chars[])

d) function(s)
• What is the output of the following code snippet?
#include<stdio.h>
#include<math.h>
int main()
{
int n,sum,i,temp,remainder;
printf("The Armstrong numbers in between 1 to 400 are : ");
for(i = 1; i <= 400; i++)
{
temp = i;
sum = 0;
while(temp!=0) {
remainder=temp%10;
sum=sum+pow(remainder,int(log10(n)+1));
temp=temp/10; }
if(i==sum) {
printf("\n%d", i); }
}
}
a) The Armstrong numbers in between 1 to 400 are :
1
153
370
b) The Armstrong numbers in between 1 to 400 are :
1
370
371
c) The Armstrong numbers in between 1 to 400 are :
1
153
371
d) The Armstrong numbers in between 1 to 400 are :
123456789
153
370
371
• How to define a C-string?

a) char str[]=”C++”;

b) char str=”C++” ;
c) str[]=”C++”;

d) char()= “C++”;
• How many parameters can a resize method take?

a) 2

b) 1
c) 1 or 2

d) 0
• Which header file is used to manipulate the string?

a) string

b) iostream
c) conio

d) getch
• Find the output of the following code. 
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string string ("computer applications&***");
cout << string.length();
return 0;
}
• a) computerapplication b) 25
• c) computer appications&***” d) error
• Find the output of the following code. 
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string m ("Mr.");
string f ("Mrs.");
m += " Gold ";
m += f;
m += '\n';
cout << m;
return 0;
}
• a) Mr. Gold b) Mr. Gold Mrs. c) Mr.Mrs. d) Gold
• Find the output of the following code. 
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("Xubuntu");
cout << str(3);
return 0;
}
• a) Xub b) Xubuntu c) bun d) error
• Find the output of the following code. 
#include <iostream>
#include <cstring>
using namespace std;
int main ()
{
char s1[15] = "WELCOME ";
char s2[30] = "COMPUTER APPLICATION";
char s3[30];
int len ;
strcpy( s3, s1);
strcat( s1, s2);
len = strlen(s1)
cout << len << endl;
return 0;
}
• a) 28 b) WELCOME c) COMPUTER APPLICATION
• d) WELCOME COMPUTER APPLICATION
• Which of the following options correctly declares an
array?

a) int b[10];

b) int b;

c) array[10]

d) b{10}
• What will be the output of the following program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("soft skill");
string::reverse_iterator r;
for (r = str.rbegin() ; r < str.rend(); r++ )
cout << *r;
return 0;
}
• a) skill b) lliks tfos c) lliks soft d) soft
• To read the characters from the keyboard, it calls
which of the following methods?

a) System.in.read()

b) System.out.read()

c) System.in.io()

d) System.out.io()
• In the following syntax, what is x mod 10 and y mod
10?

int x=42;

double y=42.5;

a) 2,2.5

b) 4,4.5

c) error

d) 2.5
• What is the output of the following program? 

int a=1;

int b=2;
System.out.println (a>b);

a) 1

b) False

c) 0

d) True
• What is the time complexity of searching an
element in the circular linked list?

a) O(logn)

b) O(1)

c) O(nlogn)

d) O(n)
• The use of free() command

a) is to create stack space

b) reclaims the space allocated to the node after use


c) releases the node to free pool

d) empties the data part of a node


• Deque is implemented using a

a) circular array or circular doubly linked list

b) circular array or singly linked list


c) singly linked list or dynamic array

d) circular doubly linked list or doubly linked list


• Create a queue of size five and perform the following
operations. The status of queue at the end is

a) Add Z, X

b) Add Y, W

c) Delete 3 letters

d) Add J

e) Delete 2 letters
• a) empty queue b) only one element in the queue

• c) two elements in the queue d) underflow


• We have created a stack DEVICE[1,3] of
peripheral devices and inserted PEN, PLOTTER, and
JOYSTICK. 
• What will happen when you try to insert the
PRINTER?

a) PRINTER would become the top element

b) Stack overflow will occur

c) Stack underflow will occur

d) JOYSTICK would be deleted from the stack


• What will be the output of the following code snippet for the input
16?
#include<stdio.h>
int main()
{
int num, i;
printf("Enter the number to find the factors : ");
scanf("%d",&num);
printf("Factors of %d are \n", num);
for(i = 1; i <= num/2; i++)
{
if(num%i == 0)
printf("%d\n", i);
}
return 0;
}
a) Enter the number to find the factors : 16
Factors of 16 are
1
2
3
6
9
b) Enter the number to find the factors : 16
Factors of 16 are
1
c) Enter the number to find the factors : 16
Factors of 16 are
1
2
4
8
d) Enter the number to find the factors : 16
Factors of 16 are
1
3
5
• If call to library function int no=strcmp(src,dest),
then value of "no" will be positive when

a) dest > src

b) dest < src

c) both are same

d) 0
• Which library function can be used as an alternative
to scan string value from user/keyboard?

a) getstr

b) scanstr

c) gets

d) getstring
• Which of the following library functions can be used
to copy one string into another?

a) strcopy()

b) strcpy()

c) stringcopy()

d) stringcpy()
• What will be the output of the following code?
int prime = 3;
if(prime)
{
System.out.println("Prime Number");
}
else
{
System.out.println("Not a prime number");
}
• a) Prime Number b) Not a prime number
• c) No output d) Compilation error
• Which of the following methods is used to display
the message at the bottom of the browser during
the start of an applet?
a) status()

b) showStatus()

c) bottom()
d) showBottom()
• State whether the following statements are true or
false. 
1. Package statement cannot be defined after import
statement in Java
2. We can have comments before the package statement
a) Both statements are true
b) Both statements are false
c) Statement 1 is true and statement 2 is false

d) Statement 1 is false and statement 2 is true


• What will be the output of the following code snippet?
#include <stdio.h>
enum week { sunday, monday, tuesday, wednesday,
thursday, friday, saturday };
int main()
{
enum week today;
today = wednesday;
printf("Day %d",today+1);
return 0;
}
• a) Day 4 b) Day 5 c) Day 6 d) Day 6
• What will be the output of the following Java line? 

System.out.println("Hello I am Java Program');

a) Garbage value
b) Hello I am Java Program

c) Compilation error

d) No Output
• What will be the output of the following program? 
switch(count)
{
case 1:
switch(target)
{
case 0:
System.out.println("Hi");
break;
case 1:
System.out.println("Java");
break;
}
break;
case 2: // ... Select the correct option
a) Nested switch case are not supported by Java
b) Syntax of nested switch is correct and no syntax error
c) Syntax of inner switch is correct but syntax of outer switch is wrong
d) Syntax of inner switch is wrong but syntax of outer switch is correct
• What type of for loop is this?

String a[]={"This","is","java", "Code"};

for (String s : a)

{
System.out.println(s);

}
• a) Enhanced for loop b) Normal for loop

• c) Incomplete for loop d) Wrong syntax of for loop


• What will be the output of the following Java
program?
class sample2
{
public static void main(String args[])
{
char c; c = "'A'";
System.out.println("c= " + c);
}
}
• a) c=A b) Compilation error
• c) c= “A” d) c=a
• Check whether the expression given below is
balanced or NOT.

-((A+B+C)*-(E+F)))

a) Balanced

b) Unbalanced
• The general form of "for" statement is

a) for (initialise counter ; test counter ; increment


counter)

b) for (initialization; condition; increment/decrement)

c) for (assigning value; condition; increment counter)

d) for (initialising value to 0; condition; decrement


operator)
• Which of the following is correct for a compound
assignment operator?

a) +=

b) ++

c) --

d) **
• Which looping statement is used to print

**

***

**** ?

a) while

b) for

c) dowhile

d) if
• What will be the output of the following program?
main()
{
auto volatile short p=0;
p++;
printf(“\n%d”,sizeof(p));
}
a) 2
b) Error: No such data type
c) Error: Conflicting data types
d) Error: Cannot modify an auto volatile type variable.
• What will be the output of the following program?
main()
{
void *p;
long x=65536+300;
p=&x;
printf(“\n%d..”,*(char *)p);
printf(“%d..”,*(int *)p);
printf(“%\d”,*(long *)p);
}
• a) 43..65 b) 44..65836..65836
• c) 44..300..65876 d) Error
• Which function is used to concatenate a string?

a) concat()

b) strcat()
c) concatenate()

d) stringcat()
• The operator used for dereferencing or indirection
is

a) @

b) *

c) &

d) .
• Which header file is used for manipulators?

a) <stdiomanip.h>

b) <iomanipulator.h>
c) <stdmanip.h>

d) <iomanip.h>
• Encapsulation is also referred as

a) data refining

b) data loading
c) data hiding

d) data reloading
• C++ provides a special __________ called the
constructor, which enables an object to initialize
itself when it is created.
a) member variables

b) member function

c) function
d) objects
• Find the output of the following code 
#include <iostream>
using namespace std;
int main()
{
double S = 0;
float D = 0;
int x ,y;
x = (int) S;
y = (int) D;
cout << x <<' '<< y;
return 0;
}
• a) 0 0 b) 11 c) Error d) 2 2
• What is the result of the following syntax? 

int twod[ ][ ]=new int[4][5];

a) A two dimensional array


b) Allocates a matrix

c) Allocates a 4 by 5 array

d) allocates rows and columns


• Which constant defined in <climits> header returns
the number of bits in a char?

a) SIZE_CHAR

b) CHAR_SIZE

c) CHAR_BIT

d) SIZE_INT
• What is the output of the following code snippet?
#include <iostream>
using namespace std;
int main()
{
char N = 120;
cout << N*7*78;
return 0;
}
• a) Error b) 840 c) H d) 65520
• In Java, the data types, byte, short, char values are
automatically promoted to

a) int

b) byte

c) bit

d) short
• In the following syntax, what is the value of b? 

byte b=50;

b=b*2;
a) 100

b) 50

c) Error

d) 2
• In the following syntax, what happens to a, b, c? 

byte a=40;

byte b=50;

byte c=100;

int d=a*b/c;

a) It is automatically converted to int

b) It is executed as it as

c) Error is shown

d) Executes, but the result is not given


• What is the output of the following program?
Class A
{
Public static void main(string args [ ])
{
int a=6;
System.out.println (++a*2 +" " +a);
}
}
• a)14 7 b) 12 6 c)6 2 d)16 6
• The format string can be created using __________
method.

a) format()

b) string()

c) scanf()

d)get()

You might also like