Give The Output of The Programs in Each Case Unless Mentioned Otherwise
Give The Output of The Programs in Each Case Unless Mentioned Otherwise
1. void main()
{
int d=5;
printf("%f",d);
}Ans: Undefined
2. void main()
{
int i;
for(i=1;i<4,i++)
switch(i)
case 1: printf("%d",i);break;
{
case 2:printf("%d",i);break;
case 3:printf("%d",i);break;
}
switch(i) case 4:printf("%d",i);
}Ans: 1,2,3,4
3. void main()
{
char *s="\12345s\n";
printf("%d",sizeof(s));
}Ans: 6
4. void main()
{
unsigned i=1; /* unsigned char k= -1 => k=255; */
signed j=-1; /* char k= -1 => k=65535 */
/* unsigned or signed int k= -1 =>k=65535 */
if(i<j)
printf("less");
else
if(i>j)
printf("greater");
else
if(i==j)
printf("equal");
}Ans: less
5. void main()
{
float j;
j=1000*1000;
printf("%f",j);
}
1. 1000000
2. Overflow
3. Error
4. None
Ans: 4
6. How do you declare an array of N pointers to functions returning pointers to
functions returning pointers to characters? Ans: The first part of this question can
be answered in at least three ways:
7. Build the declaration up incrementally, using typedefs:
typedef char *pc; /* pointer to char */
typedef pc fpc(); /* function returning pointer to char */
typedef fpc *pfpc; /* pointer to above */
typedef pfpc fpfpc(); /* function returning... */
typedef fpfpc *pfpfpc; /* pointer to... */
pfpfpc a[N]; /* array of... */
8. Use the cdecl program, which turns English into C and vice versa:
cdecl> declare a as array of pointer to function returning pointer to function
returning pointer to char char *(*(*a[])())()
cdecl can also explain complicated declarations, help with casts, and indicate which
set of parentheses the arguments go in (for complicated function definitions, like the
one above). Any good book on C should explain how to read these complicated C
declarations "inside out" to understand them ("declaration mimics use"). The pointer-
to-function declarations in the examples above have not included parameter type
information. When the parameters have complicated types, declarations can *really*
get messy. (Modern versions of cdecl can help here, too.)
9. A structure pointer is defined of the type time . With 3 fields min,sec hours
having pointers to intergers.
Write the way to initialize the 2nd element to 10.
10. In the above question an array of pointers is declared. Write the statement to
initialize the 3rd element of the 2 element to 10
11. int f()
void main()
{
f(1);
f(1,2);
f(1,2,3);
}
f(int i,int j,int k)
{
printf("%d %d %d",i,j,k);
}What are the number of syntax errors in the above?
Ans: None.
12. void main()
{
int i=7;
printf("%d",i++*i++);
}Ans: 56
13. #define one 0
#ifdef one
printf("one is defined ");
#ifndef one
printf("one is not defined ");
Ans: "one is defined"
14. void main()
{
intcount=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}
Ans: 20 20 20
15. There was question in c working only on unix machine with pattern matching.
16. what is alloca() Ans : It allocates and frees memory after use/after getting
out of scope
17. main()
{
static i=3;
printf("%d",i--);
return i>0 ? main():0;
}
Ans: 321
18. char *foo()
{
char result[100]);
strcpy(result,"anything is good");
return(result);
}
void main()
{
char *j;
j=foo()
printf("%s",j);
}
Ans: anything is good.
19. void main()
{
char *s[]={ "dharma","hewlett-packard","siemens","ibm"};
char **p;
p=s;
printf("%s",++*p);
printf("%s",*p++);
printf("%s",++*p);
}Ans: "harma" (p->add(dharma) && (*p)->harma)
"harma" (after printing, p->add(hewlett-packard) &&(*p)->harma)
"ewlett-packard"
T
e
s
t
P
a
p
e
r
:
1
P
a
p
e
r
T
y
p
e
:
T
e
c
h
n
i
c
a
l
&
C
+
+
P
o
s
t
e
d
B
y
:
a
d
m
i
n
p
a
r
t
o
f
p
a
p
e
r
f
i
r
s
t
a
p
t
i
t
u
d
e
h
a
v
i
n
g
f
i
v
e
s
e
c
t
i
o
n
s
(
5
0
q
u
e
s
t
i
o
n
s
a
n
d
4
5
m
i
n
u
t
e
s
)
p
a
r
t
2
s
e
c
o
n
d
d
e
b
u
g
g
i
n
g
(
t
e
s
t
u
r
s
k
i
l
l
s
y
a
s
h
w
a
n
t
k
a
n
i
t
k
a
r
)
(
q
u
e
s
t
i
o
n
s
2
0
t
i
m
e
3
0
m
i
n
.
)
p
a
p
e
r
1
s
e
c
t
i
o
n
o
n
e
1
5
q
u
e
s
t
i
o
n
s
(
d
a
t
a
s
u
f
f
i
c
i
e
n
c
y
)
a
l
o
n
e
i
s
s
u
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technical - C & C++
Posted By : Madhav
TRIAD
TRIAD PAPER
C - language:
3. write program to open one file input some numbers and find
smallest,largest, avg. and store them in another file.
regarding interview :
3. personal interview.
apptitude ;
Test Paper :2
Paper Type : Technical - C & C++
*16 ppl can do a work in 3 hrs?, how much time vil 5 ppl take?
* 185 miles. travelled in bus for 2 hrs a dist of 85. in how much time, he need to travel the
ramaining 100 miles, if he need to get an average of 50 miles per hr.
* a 6 mtrs wide road is laid around a garden. rad area is 564sq mtsr. if the length of the
garden is 20 mtrs?, wat is the width of it.
*Woman said pointing to a guy " his mother is the only daughter of my mother"
* a 2 digit no, the diff of its digits is one twelth of it. Find sum of the 2 digits
-data insufficient
-6
-8
-10
-none
Cpp
* #include
main()
{
int x=20, t;
&t=x;
x=50;
cout<<x<<" "<<t;
}
o/p?
50 20
t
-----
*include<iostream.h>
main()
{
cout<<sum(5)<<endl<<sum(10,5)<<endl<<sum(5,10,10);
}
ans?
20 25 25
------
* #include
main()
{
int x=20, &t;
&t=x;
int &tt;
cout<<x<<" "<<t;
}
o/p?
------
A,B,C,D,E,F are 6 members, facing the center of a circle.
A is btn B , E
C btn D, f
E is immediate right to D
q's on it
Enter Your Comments
main()
{
int x=10,y=15;
x=x++;
y=++y;
printf("%d %d\n",x,y);
}
----------------------------------------------------------------------
int x;
main()
{
int x=0;
{
int x=10;
x++;
change_value(x);
x++;
Modify_value();
printf("First output: %d\n",x);
}
x++;
change_value(x);
printf("Second Output : %d\n",x);
Modify_value();
printf("Third Output : %d\n",x);
}
Modify_value()
{
return (x+=10);
}
change_value()
{
return(x+=1);
}
----------------------------------------------------------------------------
main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
-----------------------------------------------------------------------
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
----------------------------------------------------------------------
main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x>>2);
}
--------------------------------------------------------------------
main()
{
char *ptr = "Ramco Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
---------------------------------------------------------------------
#include<stdio.h>
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
-----------------------------------------------------------------
#include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}
Test Paper :2
Paper Type : Technical - C & C++
Test Date : 8 September 2005
Posted By : Jai
4. The istream_withassign class has been derived from the istream class and overloaded
assignment operator has been added to it. The _withassign classes are much like their base
classes except that they include overloaded assignment operators. Using these operators the
objects of the _withassign classes can be copied. The istream, ostream, and iostream classes
are made uncopyable by making their overloaded copy constructor and assignment operators
private.
5. How do I write my own zero-argument manipulator that should work same as hex?
Ans: This is shown in following program.
#include
ostream& myhex ( ostream &o )
{
o.setf ( ios::hex) ;
return o ;
}
void main( )
{
cout << endl << myhex << 2000 ;
}
6.We all know that a const variable needs to be initialized at the time of declaration. Then
how come the program given below runs properly even when we have not initialized p?
#include
void main( )
{
const char *p ;
p = "A const pointer" ;
cout << p ;
}
Ans: The output of the above program is 'A const pointer'. This is because in this program p
is declared as 'const char*' which means that value stored at p will be constant and not p
and so the program works properly
10. How do I write code that allows to create only one instance of a class?
Ans: This is shown in following code snippet.
#include
class sample
{
static sample *ptr ;
private:
sample( )
{
}
public:
static sample* create( )
{
if ( ptr == NULL )
ptr = new sample ;
return ptr ;
}
} ;
sample *sample::ptr = NULL ;
void main( )
{
sample *a = sample::create( ) ;
sample *b = sample::create( ) ;
}
Here, the class sample contains a static data member ptr, which is a pointer
to the object of same class. The constructor is private which avoids us from creating objects
outside the class. A static member function called create( ) is used to create an object of the
class. In this function the condition is checked whether or not ptr is NULL, if it is then an
object is created dynamically and its address collected in ptr is returned. If ptr is not NULL,
then the same address is returned. Thus, in main( ) on execution of the first statement one
object of sample gets created whereas on execution of second statement, b holds the
address of the first object. Thus, whatever number of times you call create( ) function, only
one object of sample class will be available.
11. How do I write code to add functions, which would work as get and put properties of a
class?
Ans: This is shown in following code.
#include
class sample
{
int data ;
public:
__declspec ( property ( put = fun1, get = fun2 ) )
int x ;
void fun1 ( int i )
{
if ( i < 0 )
data = 0 ;
else
data = i ;
}
int fun2( )
{
return data ;
}
} ;
void main( )
{
sample a ;
a.x = -99 ;
cout << a.x ;
}
Here, the function fun1( ) of class sample is used to set the given integer value into data,
whereas fun2( ) returns the current value of data. To set these functions as properties of a
class we have given the statement as shown below:
__declspec ( property ( put = fun1, get = fun2 )) int x ;
As a result, the statement a.x = -99 ; would cause fun1( ) to get called to set the value in
data. On the other hand, the last statement would cause fun2( ) to get called to return the
value of data.
12. How do I write code to make an object work like a 2-D array?
Ans: Take a look at the following program.
#include
class emp
{
public :
int a[3][3] ;
emp( )
{
int c = 1 ;
for ( int i = 0 ; i <= 2 ; i++ )
{
for ( int j = 0 ; j <= 2 ; j++ )
{
a[i][j] = c ;
c++ ;
}
}
}
int* operator[] ( int i )
{
return a[i] ;
}
} ;
void main( )
{
emp e ;
cout << e[0][1] ;
}
The class emp has an overloaded operator [ ] function. It takes one argument an integer
representing an array index and returns an int pointer. The statement cout << e[0][1] ;
would get converted into a call to the overloaded [ ] function as e.operator[ ] ( 0 ). 0 would
get collected in i. The function would return a[i] that represents the base address of the
zeroeth row. Next the statement would get expanded as base address of zeroeth row[1] that
can be further expanded as *( base address + 1 ). This gives us a value in zeroth row and
first column.
16. Is there any function that can skip certain number of characters present in the input
stream?
Ans: Yes! This can be done using cin::ignore( ) function. The prototype of this function is as
shown below:
istream& ignore ( int n = 1, int d =EOF ) ;
Sometimes it happens that some extra characters are left in the input stream while taking
the input such as, the ?\n? (Enter) character. This extra character is then passed to the next
input and may pose problem.
To get rid of such extra characters the cin::ignore( ) function is used. This is equivalent to
fflush ( stdin ) used in C language. This function ignores the first n characters (if present) in
the input stream, stops if delimiter d is encountered.
17. Write a program that implements a date class containing day, month and year as data
members. Implement assignment operator and copy constructor in this class.
Ans: This is shown in following program:
#include
class date
{
private :
int day ;
int month ;
int year ;
public :
date ( int d = 0, int m = 0, int y = 0 )
{
day = d ;
month = m ;
year = y ;
}
// copy constructor
date ( date &d )
{
day = d.day ;
month = d.month ;
year = d.year ;
}
// an overloaded assignment operator
date operator = ( date d )
{
day = d.day ;
month = d.month ;
year = d.year ;
return d ;
}
void display( )
{
cout << day << "/" << month << "/" << year ;
}
} ;
void main( )
{
date d1 ( 25, 9, 1979 ) ;
date d2 = d1 ;
date d3 ;
d3 = d2 ;
d3.display( ) ;
}
18. When should I use unitbuf flag?
Ans: The unit buffering (unitbuf) flag should be turned on when we want to ensure that each
character is output as soon as it is inserted into an output stream. The same can be done
using unbuffered output but unit buffering provides a better performance than the
unbuffered output.
20. What is the difference between the manipulator and setf( ) function?
Ans: The difference between the manipulator and setf( ) function are as follows:
The setf( ) function is used to set the flags of the ios but manipulators directly insert the
formatting instructions into the stream. We can create user-defined manipulators but setf( )
function uses data members of ios class only. The flags put on through the setf( ) function
can be put off through unsetf( ) function. Such flexibility is not available with manipulators.
23. What do the nocreate and noreplace flag ensure when they are used for opening a file?
Ans: nocreate and noreplace are file-opening modes. A bit in the ios class defines these
modes. The flag nocreate ensures that the file must exist before opening it. On the other
hand the flag noreplace ensures that while opening a file for output it does not get
overwritten with new one unless ate or app is set. When the app flag is set then whatever we
write gets appended to the existing file. When ate flag is set we can start reading or writing
at the end of existing file.
24. What is the limitation of cin while taking input for character array?
Ans: To understand this consider following statements,
char str[5] ;
cin >> str ;
While entering the value for str if we enter more than 5 characters then there is no provision
in cin to check the array bounds. If the array overflows, it may be dangerous. This can be
avoided by using get( ) function. For example, consider following statement,
cin.get ( str, 5 ) ;
On executing this statement if we enter more than 5 characters, then get( ) takes only first
five characters and ignores rest of the characters. Some more variations of get( ) are
available, such as shown below:
get ( ch ) ? Extracts one character only
get ( str, n ) ? Extracts up to n characters into str
get ( str, DELIM ) ? Extracts characters into array str until specified delimiter (such as
'\n'). Leaves delimiting character in stream.
get ( str, n, DELIM ) ? Extracts characters into array str until n characters or DELIM
character, leaving delimiting character in stream.
29. When the constructor of a base class calls a virtual function, why doesn't the override
function of the derived class gets called?
Ans: While building an object of a derived class first the constructor of the base class and
then the constructor of the derived class gets called. The object is said an immature object at
the stage when the constructor of base class is called. This object will be called a matured
object after the execution of the constructor of the derived class. Thus, if we call a virtual
function when an object is still immature, obviously, the virtual function of the base class
would get called. This is illustrated in the following example.
#include
class base
{
protected :
int i ;
public :
base ( int ii = 0 )
{
i = ii ;
show( ) ;
}
virtual void show( )
{
cout << "base's show( )" << endl ;
}
} ;
class derived : public base
{
private :
int j ;
public :
derived ( int ii, int jj = 0 ) : base ( ii )
{
j = jj ;
show( ) ;
}
void show( )
{
cout << "derived's show( )" << endl ;
}
} ;
30. Can I have a reference as a data member of a class? If yes, then how do I initialise it?
Ans: Yes, we can have a reference as a data member of a class. A reference as a data
member of a class is initialized in the initialization list of the constructor. This is shown in
following program.
#include
class sample
{
private :
int& i ;
public :
sample ( int& ii ) : i ( ii )
{
}
void show( )
{
cout << i << endl ;
}
} ;
void main( )
{
int j = 10 ;
sample s ( j ) ;
s.show( ) ;
}
Here, i refers to a variable j allocated on the stack. A point to note here is that we cannot
bind a reference to an object passed to the constructor as a value. If we do so, then the
reference i would refer to the function parameter (i.e. parameter ii in the constructor), which
would disappear as soon as the function returns, thereby creating a situation of dangling
reference.
33. Why it is unsafe to deal locate the memory using free( ) if it has been
allocated using new?
Ans: This can be explained with the following example:
#include
class sample
{
int *p ;
public :
sample( )
{
p = new int ;
}
~sample( )
{
delete p ;
}
} ;
void main( )
{
sample *s1 = new sample ;
free ( s1 ) ;
sample *s2 = ( sample * ) malloc ( sizeof ( sample ) ) ;
delete s2 ;
}
The new operator allocates memory and calls the constructor. In the constructor we have
allocated memory on heap, which is pointed to by p. If we release the object using the
free( ) function the object would die but the memory allocated in the constructor would leak.
This is because free( ) being a C library function does not call the destructor where we have
deal located the memory.
As against this, if we allocate memory by calling malloc( ) the constructor would not get
called. Hence p holds a garbage address. Now if the memory is deal located using delete, the
destructor would get called where we have tried to release the memory pointed to by p.
Since p contains garbage this may result in a runtime error.
34. Can we distribute function templates and class templates in object libraries?
Ans: No! We can compile a function template or a class template into object code (.obj file).
The code that contains a call to the function template or the code that creates an object from
a class template can get compiled. This is because the compiler merely checks whether the
call matches the declaration (in case of function template) and whether the object definition
matches class declaration (in case of class template). Since the function template and the
class template definitions are not found, the compiler leaves it to the linker to restore this.
However, during linking, linker doesn't find the matching definitions for the function call or a
matching definition for object creation. In short the expanded versions of templates are not
found in the object library. Hence the linker reports error.
36. Namespaces:
The C++ language provides a single global namespace. This can cause problems with global
name clashes. For instance, consider these two C++ header files:
// file1.h
float f ( float, int ) ;
class sample { ... } ;
// file2.h
class sample { ... } ;
With these definitions, it is impossible to use both header files in a single program; the
sample classes will clash. A namespace is a declarative region that attaches an additional
identifier to any names declared inside it. The additional identifier thus avoids the possibility
that a name will conflict with names declared elsewhere in the program. It is possible to use
the same name in separate namespaces without conflict even if the names appear in the
same translation unit. As long as they appear in separate namespaces, each name will be
unique because of the addition of the namespace identifier. For example:
// file1.h
namespace file1
{
float f ( float, int ) ;
class sample { ... } ;
}
// file2.h
namespace file2
{
class sample { ... } ;
}
Now the class names will not clash because they become file1::sample and file2::sample,
respectively.
Note that if you run this program you may not get the answer shown here. This is because
packing is done for an object in memory to increase the access efficiency. For example,
under DOS, the object would be aligned on a 2-byte boundary. As a result, the size of the
object would be reported as 6 bytes. Unlike this, Windows being a 32-bit OS the object would
be aligned on a 4-byte boundary. Hence the size of the object would be reported as 12 bytes.
To force the alignment on a 1-byte boundary, write the following statement before the class
declaration.
#pragma pack ( 1 )
38. Write a program that will convert an integer pointer to an integer and vice-versa.
Ans: The following program demonstrates this.
#include
void main( )
{
int i = 65000 ;
int *iptr = reinterpret_cast ( i ) ;
cout << endl << iptr ;
iptr++ ;
cout << endl << iptr ;
i = reinterpret_cast ( iptr ) ;
cout << endl << i ;
i++ ;
cout << endl << i ;
}
1. Which of the following best explains life cycle of Defect ?
a) Defect Found -> Defect Logged -> Defect Debugged -> Defect Closed -> Defect
Rechecked
b) Defect Found -> Defect Debugged -> Defect Reported -> Defect Rechecked ->
DefectClosed
c) Defect Debugged -> Defect Found -> Defect Closed -> Defect Reported ->
DefectRechecked
d) Defect Found -> Defect Logged -> Defect Debugged -> Defect Rechecked ->
Defect Closed
2. Which group does Winrunner ,Load Runner ,SQA Suite fall under ?
a) Databases
c) Operating Systems
j = 0;
for(j=1;j<10;j++)
i=i+1;
In the (generic) code segment above what will be the value of the variable i at
completion ?
a) 0
b) 1
c) 3
d) 9
4. Which of the following statements is true when a derivation inherits both a virtual and
non-virtual instance of a base class ?
a) Each derived class object has base objects only from the non virtual instance
b) Each base class object has derived objects only from the non-virtual instance
c) Each derived class object has base objects only from the virtual instance
d) Each derived class object has a base object from the virtual instance and a base
object from non-virtual instance.
5. class Word
{
public:
Referring to the sample code above what is the minimum number of arguments
required to call the constructor ?
a) 0
b) 1
c) 2
d) 3
6. Which one of the following represents a correct and safe declaration of NULL ?
d) #define NULL((char*)0)
7. #include <iostraem>
Referring to the sample code above ,which of the following could you use to make the
standars I/O Stream classes accessible without requiring the scope resolution operator
?
d) using iostream;
8. Which one of the following statements allocates enough space to hold an array of 10
integers that are initialized to 0 ?
a) fread()
b) readfile()
c) fileread()
d) gets()
10. What is the largest value an integer can hold in a Standard C compiler ?
a) 32767
b) 65536
c) 2147483647
d) INT_MAX
11. With every use of memory allocation function should be used to release allocated
memory which is no longer needed ?
a) dropmem()
b) dealloc()
c) release()
d) free()
12. int a=1;
int ab=4;
int main()
{
printf("%i*/%i*/%*/i",a,b,ab);
}
13. kernal execute the first process when system is start---
ans :- init();
14. process id of kernal
(a) 1
(b) 0
(c) 2
(d) none
15. Which one of the following represents a correct and safe declaration of NULL ?
d) #define NULL((char*)0)
16. Which one of the following statements allocates enough space to hold an array of 10
integers that are initialized to 0 ?
Directions: Each of the following question has a question and two statements labelled as (i)
and (ii). Use the data/information given in (i) and (ii) to decide whether the data are sufficient
to answer the question record your answer as
A) If you can get the answer from (1)alone but not from (2)
B) If you can get the answer from (2)alone but not from (1)
C) If can get the answer from (1)and (2)together ,although neither statement by
itself suffice
D) If statement (1)alone suffices and statement (2) alone also suffice.
E) If can't get the answer from statements (1) and (2) together and you need more
data.
Ans:C
8. A candidate who was found to be under weightin medical test had been selected
provisionally subject to his attainment of 60Kg weight within one year. What should be
the percentage increase of his weightso that selection is confirmed after one year.
1) Weight (Kg)=16+8 Height (ft) is standard equation for the Indian population. The
candidates height is 5.5
2) His present weight is 55Kg.
Ans: D
9. Is angle µ=90
1) sin**2(µ)+cos**2(µ)=1
2) sin**2(µ)-+cos**2(µ)=1
Ans: E
10. What will be the average age of workers of an Institution after two years?
1) Present average age is 35 years
2) There are total 20 workers in the Institution
Ans: A
12. Is X^2+Y^2<X+Y?
1) 0<X<1
2) 0<Y<1 and X!=Y (X not equal to Y)
Ans: C
18. What will be the value of the greatest angle of the triangle ABC?
1) Angles of the triangle are in the ration 2:5:3
2) The side opposite to the greatest angle is the longest side.
Ans: A
Technical Questions
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
Ans. An empty string
Ans. 10 5
# define TRUE 0
some code
while(TRUE)
{
some code
}
main()
{
int x=10,y=15;
x=x++;
y=++y;
printf("%d %d\n",x,y);
}
Ans. 11 16
newval=tempval;
}
Test Paper :2
Paper Type : Technical - C & C++
Techanical paper
13. the remainder when 1221 (in hexa) is diveded by 17(decimal) in (hexa)is
ans=0
14. The binary number 100010011 will the hexa representation
ans=113
22) main()
{
int i=3,j=5;
while (i--,J--)
{
printf("%d %d".i,j);
}
}
The loop will be executed
a)3 times b)5times c)8times d)infinite times
23) main()
{
int i=3,j=5
If(i--,j--)
printf("%d %d ",i,j);
}
The output of the program for (i,J)is
a)3,5 b)3,4 c)2,4 d)2,5
ans=B
24) main()
{
int i=3
printf ("%d %d %d ",++i,i-,i+=5);
}
The the out put of the program is
a)8,8,8 b)4,3,8 c)3,2,7 d)4,4,9
ans=B
25) main()
{
int times =5;
int i=3;
int j=4;
int k=34;
i=j+k;
while(times --)
{
i=times
j=times
k=times
}
printf("%d %d %d " ,i,j,k)
}
THe output of the praogram is (i,j,k)
a)19,9,35 b)38,42,80 c)43,47,85 d)15,14,41
ans=C
26) main()
{
int num =32765;
while (num++);
printf(" %d ",num)
}
what"s the out put ofthe program
a)prints all the number above 32765 including the number 32765
b)prints all the number above 32765 excluding the number 32765
ans=B.
27) main()
{
float k=3.4156
printf("%f %f ",float(k),c(k))
}
The output of the program
a) 3.4156 ,3.4156 b)4,5 c)3,4 d)3.45 3.40
ans=C.
28) main()
{
int bounce =4;
printf ("total number of bounce =%d",bounce ++);
}
The out put of the program is
ans=D (stoP)
29) main()
{
int number =25;
char name ='A'
printf("The addition of the name and the number is %o "name +_number)
}
the output of the program is
a)compiler error
b)run time error
ans= A
30)
44) computer viruses can spread from one system to anther by means of
a) infected disks b)links to a network
c)downloaded program from a bulletin boardd)all of the program
ans)D
45) A front end processor is usually used in
ans=multi processing.
46) A radio active material of mass 16gms loses in 10 years due to
radiation.How many more years will take for the material to attain a
mass of of 1gm ?
ans=80 years
47) A block of ice floats on water in a beaker as the melts the water
level n the beaker will remain the same
ans=Remains same.
48) if va,vn,vs are velocities of sound in a air ,water ,and steel then
ans)vs>vn>va
49) in usual computer arthimetic the value of the integer expression
22/5*2+8*2/6
ans= 8.
50) an operting system is a
a)file manager b)memory manager
c)i/o manager d)all of the above
ans=D.
30. p and q are positiveintegers with their average 5, find how many
different values can p take
ans:9
31. if 0<x<1 which of the following is the largest
ans:1/x
33. If x,y,z are three consecutive natural numbers, which of the following
numbers should be x+y+z
ans:2/3
34. two persons run a race of 100m. the winner won by (110/11)m and one
second in time. find the speed of lsoer in met
ans:9.09
35. in a group of 15,7 can speak spanish, 8 can speak french and 3 can
speak neither,. how much of the group can speak both french and spanish
ans:1/5
36. which of the following intefgers is the square of an integer for every integer
ans:a**2+2n+1
37. which of the following has the largest numberical value
ans:0.2/0.000001
38. ifn is odd which of the following statements is true
ans: 3n+1 is even
39. which of the following is the prime
ans:80