You are on page 1of 17

Time: 1 hour

Total no. of questions: 40

Maximum Marks: 130

GENERAL INSTRUCTIONS:
1. In section I each question carries 3 marks & in section II each question carries 4 marks.
2. There will be a penalty of (-1) for every wrong response in section I and (-2) in section II.
3. Consider header files included & all declarations done where-ever necessary.

Name:

Registration no..

Marks obtained
Section I
Question 1:
char *ptr;
char myString[] = "abcdefg";
ptr = myString;
ptr += 5;
What string does ptr point to in the sample code above?
a) fg
b) efg
c) defg
d) cdefg
e) None of the above
------------------------------------------------------------------------------------------------------------------------------Question 2:
Given:
min (x,y) = -5;
a) will definitely give compile time error.
b) will give a run-time error.
c) will work if the function is returning a reference.
d) will work if the function accepts an integer value.

-------------------------------------------------------------------------------------------------------------------------------

Question 3:
What does the following declaration signify?
int (*pf)();
a)

pf is a pointer to function.

b) pf is a function pointer.
c)

pf is a pointer to a function which return int

d) pf is a function of pointer variable.


------------------------------------------------------------------------------Question 4:
What does the following declaration signify?
char **argv;
a)

argv is a pointer to pointer.

b) argv is a pointer to a char pointer.


c)

argv is a function pointer.

d) argv is a member of function pointer.

------------------------------------------------------------------------------------------------------Question 5:
"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");
e) printf("\"My salary was increased by 15'%'!\"\n");
-------------------------------------------------------------------------------------------------------------------------------

Question 6:
What will be the result of following expression if:
a = 3, b = 6, c = 4, d = 2
a + b > c && b c < d || b + d >= a + c
a) 1(true)
b) 0(false)
c) both 0 and 1.
d) garbage
------------------------------------------------------------------------------------------------------------------------------Question 7:
Which one is better to use:
(i) for (i=1; i<n; ++i)
(ii) for (i=1; i<n; i++)
a) (ii) will work fast.
b) both are equal.
c) (i) will execute fast.
d) will give compile time error.
Question 8:
Look at the following code:
for (char ch = a; ch<= z; ++ch)

if (ch = = a)

cout<<ch;

// (i)

int ans = 1;

else
{

int ans = 2; // (ii)

}
cout << ans;

// (iii)

a) (i) is correct while (ii) and (iii) will give error.


b) (i), (iii) will give error while (ii) is correct.
c) (i) will give error while (ii) and (iii) will work.
d) (i) and (ii) are correct while (iii) will give error.
-------------------------------------------------------------------------------------------------------------------------------

Question 9:
Look at the following code:
(i)

(ii)

(iii)

main()

main()

main()

goto last;

char ch = a;
last:

goto last;
last:

cout<<ok;
}

goto last;
{

char ch = a;

}
last:
}

a) (i) is correct while (ii) and (iii) will give error.


b) (i) will give error while (ii) and (iii) are correct.
c) (i), (ii) will give error while (iii) is correct.
d) (i) and (ii) are correct while (iii) will give error.
------------------------------------------------------------------------------------------------------------------------------Question 10:
char *buffer = "0123456789";
char *ptr = buffer;
ptr += 5;
printf( "%s\n", ptr );
printf( "%s\n", buffer );
What will be printed when the sample code above is executed?
a) 0123456789
56789
b) 5123456789
5123456789
c) 56789
56789
d) 0123456789
0123456789
e) 56789
0123456789

Question 11:
Inline functions are:
a) Its code is included in the program and compiled along with the program and no call is made to it
during run-time.
b) Its code is not compiled with the program and no call is made to it during run-time.
c) Its code is compiled with the program and no call is made to it during run-time.
d) all of the above
---------------------------------------------------------------------------------------------------------------------------Question 12:
A static data member has:
a) There is only one copy of this data member maintained for the entire class which is shared by all the
objects of that class.
b) It is visible only within the class; however, its lifetime is the entire program.
c) separate copy is made for all the objects.
d) both (a) and (b).
-----------------------------------------------------------------------------------------------------------------------------Question 13:
class X{ int x;
X( ){ i = 0; j=0; k=0;}
public:
void check(void);
};
void X :: check(void)
{

X obj1;

// (i)

}
int main()
{

X obj2;

// (ii)

}
a) both (i) and (ii) are correct.
b) only (i) is correct and (ii) will give compile time error.
c) only (ii) is correct and (i) will give compile time error.
d) both will give compile time error

Question 14:
In C++ the difference between a structure and a class is:
a) Structures cannot be defined in C++.
b) Structures cannot have member functions while a class can.
c) variable cannot be declared for a structure while objects can be made for a class.
d) by default all members are public in a structure whereas all members are private by default in a class.
---------------------------------------------------------------------------------------------------------------------Question 15:
A friend function of a class:
a) is a member of the class but is permitted to use the private members from the class.
b) is not a member of the class but is permitted to use the private and protected members from the class.
c) is not a member of the class but is permitted to use the protected members from the class.
d) is a member of the class but is not permitted to use the private and protected members from the class.
-------------------------------------------------------------------------------------------------------------------------Question 16:
Which one of the following statements allocates enough space to hold an array of 10 integers that are
initialized to 0?
a) int *ptr = (int *) malloc(10, sizeof(int));
b) int *ptr = (int *) calloc(10, sizeof(int));
c) int *ptr = (int *) malloc(10*sizeof(int));
d) int *ptr = (int *) alloc(10*sizeof(int));
e) int *ptr = (int *) calloc(10*sizeof(int));
------------------------------------------------------------------------------------------------------------------------------Question 17:
Given:
int x;
class A {public:
int x;
class B {

int x

void f(int j)
{

x=j;
::x=j;

//(i)
//(ii)

};
}
a) the above program will give compile time error.
b) (i) is global x and (ii) is B::x
c) (i) is B::x and (ii) is global x.
d) (i) is B::x and (ii) is A::x
------------------------------------------------------------------------------------------------------------------------------Question 18:
Given cases of function overloading:
(i)

void afunc(long);
void afunc(double);
afunc(15);

(ii)

void afunc (char);


void afunc(double);
afunc(471);

a) both are correct.


b) both will give compile time error.
c) (i) will give compile time error while (ii) will work.
d) (i) is correct while second will give compile-time error.
------------------------------------------------------------------------------------------------------------------------------Question 19:
If y is of integer type then the expressions
3*(y-8)/9 and (y-8)/9*3
yielt the same value if
a) y is an even number
b) y is an odd number
c) y-8 is an integral multiple of 9
d) y-8 is an integral multiple of 3
-------------------------------------------------------------------------------------------------------------------------------

Question 20:
for ( i=1; i<5; ++i)
if ( i = = 3) continue;
else printf (%d, i);
results in the printing of
a)12345
b)124
c)245
d)125
-------------------------------------------------------------------------------------------------------------------------Question 21:
The declaration
int (*p) [5];
means
a) p is a one dimensional array of size 5, of pointers to integers
b) p is a pointer to a 5 element integer array
c) the same as int *p [5];
d) none of the above
--------------------------------------------------------------------------------------------------------------------------Question 22:
The following program fragment
int k=-7;
printf(%d, 0 < !k);
a) prints 0
b) prints a non-zero value
c) will give compile time error
d) prints an unpredictable value
-------------------------------------------------------------------------------------------------------------------------------

Question 23:
main()
{
int i=2;
{ int i=4, j=5;
printf(%d%d, i , j);
}
printf(%d%d, i , j);
}
a) will give compile time error
b) prints 4525
c) prints 2525
d) none of the above
---------------------------------------------------------------------------------------------------------------------------Question 24:
The following program fragment
if (a=0)
printf(a is zero);
else
printf(a is not zero);
results in the printing of
a) a is zero
b) a is not zero
c) nothing
d) garbage
-----------------------------------------------------------------------------------------------------------------------------Question 25:
# define prod(a,b) a*b
main()
{
int x = 3, y = 4;
printf(%d, prod (x-2,y-1));

}
a) 10
b) 15
c) -12
d) -6
------------------------------------------------------------------------------------------------------------------------------Question 26:
main() {
printf(\n ab);
printf(\b si);
printf(\b ha);
}
a) asha
b) absiha
c) abia
d) absha
------------------------------------------------------------------------------------------------------------------------------Question 27:
The rule for implicit type conversion is
a) int<unsigned<float<double
b) unsigned<int<float<double
c) int<unsigned<double<float
d) unsigned<int<double<float
-----------------------------------------------------------------------------------------------------------------------------Question 28:
If n set the value 2 then the statement a[++n] = n++; will assign
a) 3 to a[4]
b) assign 2 to a[4]
c) 3 to a[4]
d) 4 to a[3]

Question 29:
main(){
int a,b,c,d;
a=3;
b=5;
c=a,b;
d=(a,b);
printf(%d%d,c,d);
}
The output for this program:
a) 3 5
b) 5 5
c) 3 3
d) compile time error
------------------------------------------------------------------------------------------------------------------------------Question 30:
main()
{
int a[ ][3] = {1,2,3,4,5,6};
int (*ptr)[3] = a;
printf(%d%d, (*ptr)[1],(*ptr)[2]);
++ptr;
printf(%d%d, (*ptr)[1],(*ptr)[2]);
}
The output for this program will be:
a) unexpected results
b) 2 35 6
c) 2 34 5
d) 2 33 4

------------------------------------------------------------------------------------------------------------------

Section-II
Question 31:
char* myFunc (char *ptr)
{
ptr += 3;
return (ptr);
}
int main()
{
char *x, *y;
x = "HELLO";
y = myFunc (x);
printf ("y = %s \n", y);
return 0;
}
What will print when the sample code above is executed?
a) y = HELLO
b) y = ELLO
c) y = LLO
d) y = LO
e) x = O

Question 32:
int x = 5;
int y = 2;
char op = '*';
switch (op)
{
default : x += 1;
case '+' : x += y;
case '-' : x -= y;
}

After the sample code above has been executed, what value will the variable x contain?
a) 4
b) 5
c) 6
d) 7
e) 8
----------------------------------------------------------------------------------------------------------------------------- ---------------

Question 33:
#include <stdio.h>
int i;
void increment( int i )
{
i++;
}
int main()
{
for( i = 0; i < 10; increment( i ) )
{
}
printf("i=%d\n", i);
return 0;
}
What will happen when the program above is compiled and executed?
a) It will not compile.
b) It will print out: i=9.
c) It will print out: i=10.
d) It will print out: i=11.
e) It will loop indefinitely.
----------------------------------------------------------------------------------------------------------------------------- ---------------

Question 34:
void main()
{
int i = 4;
switch (i)
{
default:
;
case 3:
i += 5;
if ( i == 8)
{
i++;
if (i == 9) break;
i *= 2;
}
i -= 4;
break;
case 8:
i += 5;
break;
}
printf("i = %d\n", i);
}
What will the output of the sample code above be?
a) i = 5
b) i = 8
c) i = 9
d) i = 10
e) i = 18
----------------------------------------------------------------------------------------------------------------------------- ---------------

Question 35:
Inlining a function does not work for situations:
(i) for functions that return values and are having a loop or a switch or a goto.
(ii) for functions contain static variables.
(iii) if the function is recursive.
Which of the above statements are true:
a) only (i) and (ii) are correct.
b) only (ii) and (iii) are correct.
c) only (i) and (iii) are correct.
d) all are correct.
-------------------------------------------------------------------------------------------------------------------- ------------------------

Question 36:
Predict the output of the following:
#include<iostream.h>
#include<conio.h>
void amount (float princ, int time=2, float rate=0.08);
void amount (float princ, int time, float rate)
{

cout<< princ <<, <<time<<, <<rate;

}
void main()
{

amount(2500,0.09);

}
a) 2500, 0, 0.08
b) 2500, 2, 0.08
c) 2500 , 0, 0.09
d) 2500, 2, 0.09
----------------------------------------------------------------------------------------------------------------------------- ---------------

Question 37:
#include<stdio.h>
int f( int *a, int n)
{
if (n <= 0) return 0;
elseif (*a%2 == 0) return *a+f(a+1), n-1);
else return *a-f( a+1, n-1);
}
int main()
{
int a[ ] = {12,7,13,4,11,6}
printf(%d, f(a,6));
return 0;
}
a) -9
b) 5
c) 15
d) 19
----------------------------------------------------------------------------------------------------------------------------- ---------------

Question 38:
Predict the output of the following program fragment:
static char wer [ ] [5] = {harmot,merli,axari);
printf ({%d%d%d, wer, wer[0], &wer [0][0]);
is
a) 262164 262164 262164
b) 262124 212465 262166
c) 262164 262165 262165
d) 262164 262164 262165
--------------------------------------------------------------------------------------- -----------------------------------------------------

Question 39:
main()
{
char p[ ] = me;
int i;
for (i=0;p[i];i++)
printf(\t%c%c%c%c, p[i], *(p+i), *(i+p), i[p]);
}
a) mmmmeeee
b) mmmm
c) unexpected results
d) compile time error
----------------------------------------------------------------------------------------------------------------------------- ---------------

Question 40:
main() {
int i = -1, j= -1, k=0, l=2, m;
m = i++ && j++ && k++ | | l++;
printf(%d%d%d%d%d, i,j,k,l,m);
}
a) 0 0 1 3 1
b) -1 0 1 3 1
c) compiler error
d) 1 0 1 3 1
----------------------------------------------------------------------------------------------------------------------------- ---------------

You might also like