++a +b
=6 + Garbage floating point number
=Garbage floating point number
//From the rule of automatic type conversion
Hence sizeof operator will return 4 because size of float data type in c is 4 byte.
Value of any variable doesn’t modify inside sizeof operator. Hence value of variable a will remain 5.
Q. No. :
6
Question :
On executing the below program what will be the contents of 'target.txt'
file if the source file contains a line "To err is human"?
#include<stdio.h>
int main() { int i, fss; char ch, source[20] = "source.txt", target[20]="target.txt", t; FILE *fs, *ft; fs = fopen(source, "r"); ft = fopen(target, "w"); while(1) { ch=getc(fs); if(ch==EOF) break; else { fseek(fs, 4L, SEEK_CUR); fputc(ch, ft); } } return0; }
The file source.txt is opened in read mode and target.txt is opened in write mode. The file source.txt contains "To err is human".
Inside the while loop,
ch=getc(fs); The first character('T') of the source.txt is stored in variable ch and it's checked for EOF.
if(ch==EOF) If EOF(End of file) is true, the loop breaks and program execution stops.
If not EOF encountered, fseek(fs, 4L, SEEK_CUR); the file pointer advances 4 character from the current position. Hence the file pointer is in 5th character of file source.txt.
fputc(ch, ft); It writes the character 'T' stored in variable ch to target.txt.
The while loop runs three times and it write the character 1st and 5th and 11th characters ("Trh") in the target.txt file.
Size of a character array should
one greater than total number of characters in any string which it stores. In c
every string has one terminating null character. This represents end of the
string.
So in the string “Network” , there
are 8 characters and they are ‘N’,’e’,’t’,’w’,’o’,’r’,’k’ and ‘\0’. Size of
array arr is seven. So array arr will store only first sevent characters and it
will note store null character.
As we know %s in prinf statement
prints stream of characters until it doesn’t get first null character. Since
array arr has not stored any null character so it will print garbage value.
Q. No. :
18
Question :
What will be output of the
following program?
#include<stdio.h> int main(){
int i=5,j;
j=++i+++i+++i;
printf("%d
%d",i,j);
return 0;
}
Rule :- ++ is pre increment operator so in any arithmetic expression it first
increment the value of variable by one in whole expression then starts assigning
the final value of variable in the expression.
Compiler will treat this expression j = ++i+++i+++i; as
i = ++i + ++i + ++i;
Initial value of i = 5 due
to three pre increment operator final value of i=8.
Now final value of i i.e. 8
will assigned to each variable as shown in the following figure:
So, j=8+8+8
j=24 and
i=8
Q. No. :
19
Question :
How will you free the memory allocated by the following program?
Step 1: int fun(int); This is prototype of function fun(). It tells the compiler that the function fun() accept one integer parameter and returns an integer value.
Step 2: int i=3; The variable i is declared as an integer type and initialized to value 3.
Step 3: fun(i=fun(fun(i)));. The function fun(i) increements the value of i by 1(one) and return it.
Lets go step by step,
=> fun(i) becomes fun(3) is called and it returns 4.
=> i = fun(fun(i)) becomes i = fun(4) is called and it returns 5 and stored in variable i.(i=5)
=> fun(i=fun(fun(i))); becomes fun(5); is called and it return 6 and nowhere the return value is stored.
Step 4: printf("%d\n", i); It prints the value of variable i.(5)
Hence the output is '5'.
Q. No. :
21
Question :
What will be output of the
following program?
#include<stdio.h> int main()
{
int a=2,b=7,c=10;
c=a==b;
printf("%d",c);
return 0;
}
Keyword break
is not syntactical part of if-else statement. So we cannot use break
keyword in if-else statement. This keyword can be use in case of loop or
switch case statement.
Hence when you will compile above code compiler will show an error message: Misplaced break.
Q. No. :
25
Question :
What will be the output of the program if the array begins at 65486 and each integer occupies 2 bytes?
#include<stdio.h>
int main() { int arr[] = {12, 14, 15, 23, 45}; printf("%u, %u\n", arr+1, &arr+1); return0; }
Step 1: int arr[] = {12, 14, 15, 23, 45}; The variable arr is declared as an integer array and initialized.
Step 2: printf("%u, %u\n", arr+1, &arr+1); Here, the base address(also the address of first element) of the array is 65486. => Here, arr is reference to arr has type "pointer to int".
Therefore, arr+1 is pointing to second element of the array arr memory location. Hence 65486 + 2 bytes = 65488
=> Then, &arr is "pointer to array of 5 ints".
Therefore, &arr+1 denotes "5 ints * 2 bytes * 1 = 10 bytes".
Hence, begining address 65486 + 10 = 65496. So, &arr+1 = 65496
Hence the output of the program is 65486, 65496
The statement 'B' is correct, because int num[6]; specifies the size of array and num[6]=21; designates the particular element(7th element) of the array.
Which of the following is not a type of inheritance?
A :
Hierarchical
B :
Derived
C :
Multipath
D :
Multilevel
Answer: B
Q. No. :
32
Question :
Multilevel Inheritance means
A :
Procedure of deriving a class from derived class
B :
Deriving a class from a single base class
C :
Single base class deriving two classes
D :
None of the above
Answer: A
Q. No. :
33
Question :
Overloaded functions are
A :
Very long functions that can hardly run
B :
One function containing another one or more functions inside it.
C :
Two or more functions with the same name but different number of parameters or type.
D :
None of above
Answer: D
Q. No. :
34
Question :
Observe the following block of code and determine what happens when x=2?
switch (x){
case 1:
case 2:
case 3:
cout<< "x is 3, so jumping to third branch";
goto thirdBranch;
default:
cout<<"x is not within the range, so need to say Thank You!";
}
A :
Program jumps to the end of switch statement since there is nothing to do for x=2
B :
The code inside default will run since there is no task for x=2, so, default task is run
C :
Will display x is 3, so jumping to third branch and jumps to third Branch.
D :
None of above
Answer: C
Q. No. :
35
Question :
In case of arguments passed by values when calling a function such as z=addidion(x,y),
A :
Any modifications to the variables x & y from inside the function will not have any effect outside the function.
B :
The variables x and y will be updated when any modification is done in the function
C :
The variables x and y are passed to the function addition
D :
None of above are valid.
Answer: A
Q. No. :
36
Question :
Consider the following two pieces of codes and choose the best answer
Code 1:
switch (x) {
case1:
cout <<”x is 1”;
break;
case 2:
cout <<”x is 2”;
break;
default:
cout <<”value of x unknown”;
}
CODE 2:-
If (x==1){
Cout <<”x is 1”;
}
Else if (x==2){
Cout << “x is 2”;
}
Else{
Cout <<”value of x unknown”;
}
A :
Both of the above code fragments have the same behaviour
B :
Both of the above code fragments produce different effects
C :
The first code produces more results than second
D :
The second code produces more results than first.
Answer: A
Q. No. :
37
Question :
Regarding the use of new line character (/n) and endl manipulator with cout statement
A :
Both ways are exactly same
B :
Both are similar but endl additionally performs flushing of buffer
C :
endl can’t be used with cout
D :
\n can’t be used with cout
Answer: B
Q. No. :
38
Question :
Dynamic binding is
A :
Resolving the function call at compile time
B :
Defining binding statically
C :
Resolving a function call at runtime
D :
None
Answer: C
Q. No. :
39
Question :
Identify the correct statement regarding scope of variables
A :
Global variables are declared in a separate file and accessible from any program.
B :
Local variables are declared inside a function and accessible within the function only.
C :
Global variables are declared inside a function and accessible from anywhere in program.
D :
Local variables are declared in the main body of the program and accessible only from functions.
Answer: B
Q. No. :
40
Question :
If you use same variable for two getline statements
A :
Both the inputs are stored in that variable
B :
The second input overwrites the first one
C :
The second input attempt fails since the variable already got its value
D :
You can not use same variable for two getline statements
Answer: B
Q. No. :
41
Question :
In an assignment statement
A :
The lvalue must always be a variable
B :
The rvalue might be a constant, a variable, an expression or any combination of these
C :
The assignment always takes place from right to left and never the other way
D :
All of above
Answer: D
Q. No. :
42
Question :
By default C++ classes are
A :
Private
B :
Public
C :
Protected
D :
None
Answer: A
Q. No. :
43
Question :
Regarding following statement which of the statements is true? const int pathwidth=100;
A :
Declares a variable pathwidth with 100 as its initial value
B :
Declares a construction pathwidth with 100 as its initial value
C :
Declares a constant pathwidth whose value will be 100
D :
Constructs an integer type variable with pathwidth as identifier and 100 as value
Answer: C
Q. No. :
44
Question :
Which of the following statement is true regarding cin statement?
A :
cin statement must contain a variable preceded by >> operator
B :
cin does not process the input until user presses RETURN key
C :
you can use more than one datum input from user by using cin
D :
all of above
Answer: D
Q. No. :
45
Question :
Void pointer is
A :
It is a pointer which cannot be defined
B :
Specific data type and it couldn't hold the access of some other type of variable
C :
A pointer pointing to an array
D :
None
Answer: D
Q. No. :
46
Question :
When inorder traversing a tree resulted E A C K F H D B G; the preorder traversal would return
A :
FAEKCDBHG
B :
FAEKCDHGB
C :
EAFKHDCBG
D :
FEAKDCHBG
Answer: B
Q. No. :
47
Question :
How many operations are required in Round Robin algorithm used in minimum spanning tree, if an appropriate implementation of the priority queue is used.
A :
O(e logn)
B :
O(log logn)
C :
O(n log e)
D :
O(e log logn)
Answer: D
Q. No. :
48
Question :
In a Heap tree
A :
Values in a node is greater than every value in left sub tree and smaller than right sub tree
B :
Values in a node is greater than every value in children of it
C :
Both of above conditions applies
D :
None of above conditions applies
Answer: B
Q. No. :
49
Question :
When representing any algebraic expression E which uses only binary operations in a 2-tree
A :
the variable in E will appear as external nodes and operations in internal nodes
B :
the operations in E will appear as external nodes and variables in internal nodes
C :
the variables and operations in E will appear only in internal nodes
D :
the variables and operations in E will appear only in external nodes
Answer: A
Q. No. :
50
Question :
Which of the following statements are true in case of Depth- First-Traversal i). DFS is used to determine connected components of an undirected graph ii). DFS is used to determine acyclic nature of a graph.
A :
(i)
B :
(ii)
C :
(i) and (ii)
D :
none
Answer: C
Q. No. :
51
Question :
The post order traversal of a binary tree is DEBFCA. Find out the pre order traversal
A :
ABFCDE
B :
ADBFEC
C :
ABDECF
D :
ABDCEF
Answer: C
Q. No. :
52
Question :
When converting binary tree into extended binary tree, all the original nodes in binary tree are
A :
internal nodes on extended tree
B :
external nodes on extended tree
C :
vanished on extended tree
D :
None of above
Answer: A
Q. No. :
53
Question :
Which data structure is needed to convert infix notation to prefix notation?
A :
Stack
B :
Queue
C :
Tree
D :
Graph
Answer: A
Q. No. :
54
Question :
5-2-3*5-2 evaluates 18 then
A :
- left associative * has precedence over -
B :
- right associative * has precedence over -
C :
* left associative - has precedence over *
D :
* right associative - has precedence over *
Answer: D
Q. No. :
55
Question :
For the sequence 500, 535, 512, 721, 436, 611, 624, 632, 643 Lexicographic sort gives time complexity of
A :
O(39)
B :
O(29)
C :
O(28)
D :
O(27)
Answer: D
Q. No. :
56
Question :
What is time required to insert an element in a stack with linked implementation?
A :
1
B :
Log2n
C :
n
D :
n Log2n
Answer: B
Q. No. :
57
Question :
In
recursive implementations which of the following is true for saving the state
of the steps
A :
as full state on the stack
B :
as reversible action on the stack
C :
both A and B
D :
None
Answer: C
Q. No. :
58
Question :
Space complexity refers to
A :
Memory required by an algorithm needs to run to completion.
B :
Complexities involved in space mission transmission
C :
Complexity of a 3 D graphics creation
D :
None
Answer: C
Q. No. :
59
Question :
which
one of the following is the recursive travel technique.
A :
depth first search
B :
preorder
C :
breadth first
search
D :
None
Answer: A
Q. No. :
60
Question :
A heap is
A :
Collection of waste material
B :
A complete binary tree with property that the value at each node should be as large as the value of its children.
C :
A spanning tree of order n
D :
None
Answer: B
Q. No. :
61
Question :
A list is ordered from smallest to largest when a sort is called. Which sort would take shortest time to sot from maximum to minimum.
A :
Heap Sort
B :
Bubble Sort
C :
Quick sort
D :
Selection sort
Answer: C
Q. No. :
62
Question :
Stack is useful for implementing
A :
Radix sort
B :
Breadth First Search
C :
Recursion
D :
Depth First Search
Answer: C
Q. No. :
63
Question :
The elements of an array are stored successively in memory cells because
A :
by this way computer can keep track only the address of the first element and the addresses of other elements can be calculated
B :
the architecture of computer memory does not allow arrays to store other than serially
C :
both of above
D :
none of above
Answer: A
Q. No. :
64
Question :
For the sequence 8, 2, 4, 6, 9,7, 10, 1, 5, 3 Perform the splitting part of merge sort. The second stage of the merge operation will give which of the following output?