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.
Q. No. :
5
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;
}
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. :
8
Question :
int var1;
If a variable has been declared with file scope, as above, can it safely be accessed globally from another file?
A :
Yes; it can be referenced through the register specifier
B :
No; it would have to have been initially declared as a static variable
C :
No; it would need to have been initially declared using the global keyword.
D :
Yes; it can be referenced through the publish specifier
Answer: C
Q. No. :
9
Question :
What will be the output of the program?
#include<stdio.h>int main()
{
int fun(int);
int i=3;
fun(i=fun(fun(i)));
printf("%d\n", i);
return0;
}
fun(int i)
{
i++;
return i;
}
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. :
10
Question :
What will the function rewind() do?
A :
Reposition the file pointer to a character reverse.
B :
Reposition the file pointer stream to end of file.
C :
Reposition the file pointer to begining of that line.
rewind() takes the file pointer to the
beginning of the file. so that the next I/O operation will take place at
the beginning of the file. Example: rewind(FilePointer);
fileno is a macro that returns the file handle for the stream.
fp = fopen("DUMMY.C", "w"); A file DUMMY.C is opened in write mode and returns the file pointer to fp
t = fileno(fp); returns the handle for the fp stream and it stored in the variable t
printf("%d\n", t); It prints the handle number.
Q. No. :
13
Question :
What will be the output
#include
void main()
{
int check=2;
switch(check)
{
case 1: printf("D.W.Steyn");
case 2: printf(" M.G.Johnson");
case 3: printf(" Mohammad Asif");
default: printf(" M.Muralidaran");
}
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
3.14f is floating point constant. Its size is 4 byte. 3.14 is double constant (default).
Its size is 8 byte. 3.14L is long double constant. Its size is 10 byte. sizeof()
operator always return the size of data type which is written inside the(). It
is keyword.
Q. No. :
22
Question :
If the two strings are identical, then strcmp() function returns
++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.
"fflush()" flush any buffered output associated with filename, which
is either a file opened for writing or a shell command for redirecting
output to a pipe or coprocess.
Example: fflush(FilePointer); fflush(NULL); flushes all streams.
Q. No. :
28
Question :
Can you combine the following two statements into one?
char *p; p = (char*) malloc(100);
A :
char p = *malloc(100);
B :
char *p = (char) malloc(100);
C :
char *p = (char*)malloc(100);
D :
char *p = (char *)(malloc*)(100);
Answer: C
Q. No. :
29
Question :
Which of the following statements are correct about 6 used in the program?
int num[6]; num[6]=21;
A :
In the first statement 6 specifies a particular element, whereas in the second statement it specifies a type.
B :
In the first statement 6 specifies a array size, whereas in the second statement it specifies a particular element of array.
C :
In the first statement 6 specifies a particular element, whereas in the second statement it specifies a array size.
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.
Q. No. :
30
Question :
"My salary was increased by 15%!"
Select the statement which will EXACTLY reproduce the line of text above.
A :
printf("My salary was increased by 15%!\n");
B :
printf("My salary was increased by 15'%'!\n");
C :
printf("\"My salary was increased by 15%%!\"\n");
D :
printf("\"My salary was increased by 15'%'!\"\n");
Answer: C
Q. No. :
31
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. :
32
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. :
33
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. :
34
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. :
35
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. :
36
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. :
37
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. :
38
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. :
39
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. :
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 :
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. :
42
Question :
Which of the following is not a type of inheritance?
A :
Hierarchical
B :
Derived
C :
Multipath
D :
Multilevel
Answer: B
Q. No. :
43
Question :
By default C++ classes are
A :
Private
B :
Public
C :
Protected
D :
None
Answer: A
Q. No. :
44
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. :
45
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. :
46
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. :
47
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?
A :
2 8 4 6 9 7 10 1 5 3
B :
2 4 6 9 8 1 3 5 7 10
C :
2 4 8 6 9 1 7 10 3 5
D :
2 8 4 6 9 7 10 1 5 3
Answer: C
Q. No. :
48
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. :
49
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. :
50
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. :
51
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. :
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 :
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. :
54
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. :
55
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. :
56
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. :
57
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. :
58
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. :
59
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. :
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 :
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. :
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 :
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. :
64
Question :
In
recursive implementations which of the following is true for saving the state
of the steps