1)

Which special symbols are allowed in a variable name ?

 

a) !
b) |
c) *
d) _ (Underscore)

Answer(s) : 
d) _ (Underscore)

[quads id=1]

2)

Which is the only ternary operator in C ?

 

a)

?:

b)

&&

c) *=
d) <<

Answer(s) : 
a) 
			
				
					?:

				
			
		

3)

Which of the following declarations are correct ?

 

a)

struct {int a;}

b)

struct mystruct {int a;}

c)

 struct mystruct {int a;} 

d)

struct mystruct: int a; 

Answer(s) : 
b) 
			
				
					struct mystruct {int a;};
				
			
		

[quads id=1]

4)

What will the function func return ?

void func(int x, int y) {
x–; y–;

return (x+y);
}

 

a)

The sum of x and y

b)

The sum of the decremented value of x and y 

c)

Returns a pointer to the sum of the decremented value of x and y

d)

Compilation Error: return value type does not match the function type 

Answer(s) : 
d) 
			
				
					Compilation Error: return value type does not match the function type
				
			
		

5)

What value will be printed for data.c? #include

#include

int main() {
union Data {

int i;

unsigned char c;
} data;

data.i = 89;
data.c =’A’;
printf( “%d\n”, data.i);
return 0;

}

 

a)

65 

b)

89 

c) 0
d) Garbage

Answer(s) : 
a) 
			
				
					65
				
			
		

[quads id=1]

6)

What will be the output of the following program ?
#include
int main() {

int i_ = 2, *j_, k_;
j_ = &i_;
printf(“%d\n”, i_**j_*i_+*j_);
return 0;

}

 

a)

Compilation Error: Erroneous syntax 

b) 16
c) 10
d) 8

Answer(s) : 
c) 10

7)

What is the output of the following program ?
#include
#define func(x, y) x + y/x
int main() {

int i = -1, j = 2;
printf(“%d\n”,func(i + j, 3));
return 0;

}

 

a)

divide by zero error 

b) 0
c) 4
d) -4

Answer(s) : 
b) 0

[quads id=1]

8)

What will be the output of the following program?#include int sum(int a, int b, int c) {

return a*b*c;
}

int main() {     int (*function_pointer)(int, int, int);

function_pointer = sum;
printf(“%d”, function_pointer(1, 4.5, 5));
return 0;

}

 

a) 22.5
b)

Compilation Error: Error in function arguments 

c) 20
d)

Compilation Error: Invalid assignment of sum 

Answer(s) : 
c) 20

9)

Fill in the blank to concatenate strings str1 and str2 to form str3 ?
#include
#include
using namespace std;

int main(void) {
string str1 = “I Love to “;
string str2 = “Cycle”;

string str3 = _______________________;
cout << str3;
return 0;

}
Output: I Love to Cycle

 

a)

str1+str2

b)

strcat(str1,str2) 

c)

str1.append(str2)

d)

strcat(strcpy(str3,str1),str2) 

Answer(s) : 
a) 
			
				
					str1+str2

				
			
		
c) 
			
				
					str1.append(str2)

				
			
		

[quads id=1]

10)

What will be the output of the following program ?

#include
#include
using namespace std;
bool srt (int i, int j) {

return (i < j);
}

int main() {
int data[] = {52, 76, 19, 5, 10, 100, 56, 98, 17};
sort (data + 1, data + 5, srt);
for (int i = 0; i < 7; i++)
cout << data[i] << ” “;
return 0;

}

 

a)

5 10 19 52 56 76 98 100 17 

b)

5 10 19 52 76 100 56 98 17 

c)

52 5 10 19 76 100 56 98 17 

d)

52 5 10 19 76 100 56 

Answer(s) : 
d) 
			
				
					52 5 10 19 76 100 56
				
			
		

11)

What will be the output of the following program?
#include
#include
#include
using namespace std;
int main() {

char str[19]= “Accessing”;
stack s;
for(int i = 0; i < strlen(str); i++)
s.push(str[i]);
for(int i = 0; i < strlen(str) – 1; i++) {

s.top(); s.pop();

cout << s.top();
}

return 0;
}

 

a)

gnisseccA 

b)

nisseccA 

c)

gnissecc

d)

nisseccAnisseccA 

Answer(s) : 
b) 
			
				
					nisseccA
				
			
		

[quads id=1]

12)

Choose the correct statement for A# and B# :
#include
#include
using namespace std;
int main() {

cout << “Enter the no. of elements: “; int count, j, sub=0; cin >> count;
__________________ A# // Declare with Default size
__________________ B# // Change the size to the required amount
for(int i = 0; i < v.size(); i++) {

v[i] = i;

sub – = v[i];
}

cout << “Array Sum: ” << sub<< endl;

return 0;
}

 

a)

  1. A#: vector <int> v; 
  2. B#: v.resize(count); 

b)

  1. A#: vector <int> v(count); 
  2. B#: v.resize(count); 

c)

  1. A#: vector <int> v(count); 
  2. B#: v.size(count); 

d)

  1. A#: vector <int> v; 
  2. B#: v.size(count); 
Answer(s) : 
a) 
			
				
					
						
							A#: vector int v;
						B#: v.resize(count);