1. On which memory segment is dynamic memory allocated in C++?
2. In which memory location is the variable 'i' stored?
Int main() {
int i =10;
cout << &i << endl;
return 0;
}
3. Dynamic memory allocated on the heap is not deallocated in this example. Where should it be deallocated?
#include <iostream>
using namespace std;
int* addOnetoX(int x){
int res = x+1;
int *h = new int;
*h = res;
return h;
}
int main() {
int x = 100;
int *p = addOnetoX(x);
cout << *p << endl;
return 0;
}
4. Where is h stored in the following example?
#include <iostream>
using namespace std;
int* addOnetoX(int x){
int res = x+1;
int *h = new int;
*h = res;
return h;
}
int main() {
int x = 100;
int *p = addOnetoX(x);
cout << *p << endl;
return 0;
}
5. Where is h and x stored in the following example?
#include <iostream>
using namespace std;
int main() {
int *h = new int(2);
int x=0;
cout << h << endl;
cout << &h << endl;
cout << &x << endl;
delete h;
return 0;
}
1 out of 9
1. Which of the following is the correct syntax of including a user defined header files in C++?
2. Which of the following is called address operator?
3. Which of the following is used for comments in C++?
4. What are the actual parameters in C++?
5. Which function is used to read a single character from the console in C++?
6. Which function is used to write a single character to console in C++?
7. What is a constant that contains a single character enclosed within single quotes?
8. A C++ code line ends with ___
9. What are the escape sequences?
10. Which of the following escape sequence represents carriage return?
11. Which of the following escape sequence represents tab?
12. Which of the following is called insertion/put to operator?
13. Which of the following is called extraction/get from operator?
14. What is the size of a boolean variable in C++?
15. Which of the following is an exit-controlled loop?
16. Which of the following is an entry-controlled loop?
17.In which part of the for loop termination condition is checked? for(I;II;III)
18. Which of the following is the scope resolution operator?
2 out of 9
1. Which data type is used to represent the absence of parameters?
2. How the constants are declared?
3. Which type is best suited to represent the logical values?
4. Identify the user-defined types from the following?
5. Which of the following statements are true for the function f : int f (float)?
6. How many characters are specified in the ASCII scheme?
7. Given the variables p, q are of char type and r, s, t are of int type. Select the right statement?
1. t = (r * s) / (r + s);
2. t = (p * q) / (r + s);
8. Suppose in a hypothetical machine, the size of char is 32 bits. What would sizeof(char) return?
9. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int x = -1;
unsigned int y = 2;
if (x > y) {
cout << "x is greater: " ;
}
else
{
cout << "y is greater: " ;
}
return 0;
}
10. 0326, 786427373824, ‘x’ and 0X2f are _____ _____ ____ and _____ literals respectively.
11. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int x = 8;
cout << "ANDing integer 'x' with 'true' : " << (x && true);
return 0;
}
12. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int i = 3;
int l = i / -2;
int k = i % -2;
cout << l << ‘ ‘ << k ;
return 0;
}
3 out of 9
1. How many sequences of statements present in C++?
2. What will be the output of the following C++ code?
#include
using namespace std;
int main() {
if (0) {
cout << "Hello" ;
}
else
{
cout << "Good Bye" ;
}
return 0;
}
3. if you have to make decision based on multiple choices, which of the following is best suited?
4. Can we use string inside switch statement?
5. In situations where we need to execute body of the loop before testing the condition, we should use_____.
6. Loops in C++ Language are implemented using?
7. Which following loop is faster in C++ Language?
8. What is the way to suddenly come out of or quit any loop in C++?
9. The if…else statement can be replaced by which operator?
10. The switch statement is also called as?
11. Choose a correct C++ for loop syntax.
12. Choose a correct C++ do while syntax.
13. Choose a correct C++ Statement.
14. A switch statement can be used with which of the following types of variable?
15. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int n ;
for (n = 5; n > 0; n–)
{
cout << n;
if (n == 3)
break;
}
return 0;
}
16. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int n = 15;
for (;;) {
cout << n;
}
return 0;
}
17. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int I ;
for (i = 0; i < 10; i++);
{
cout << i;
}
return 0;
}
18. Which looping process is best used when the number of iterations is known?
19. Which of the following is optional in switch construct?
20. What is the effect of writing a break statement inside a loop?
4 out of 9
1. In which direction does the assignment operation will take place?
2. What is this operator "?:" called ?
3. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a, b, c;
a = 2;
b = 7;
c = (a > b) ? a : b;
cout << c;
return 0;
}
4. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a;
a = 5 + 3 * 5;
cout << a;
return 0;
}
5. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int i, j;
j = 10;
i = (j++, j + 100, 999 + j);
cout << i;
return 0;
}
6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int x, y;
x = 2;
y = ++x * ++x;
cout << x << y;
y = x++ * x++;
cout << x << y;
y = ++x * x++;
cout << x << y;
y = x++ * ++x;
cout << x << y;
return 0;
}
5 out of 9
1. Where does the execution of the program starts?
2. What are mandatory parts in the function declaration?
3. which of the following is used to terminate the function declaration?
4. Which is more effective while calling the functions?
5. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void fun(int x, int y){
x = 20;
y = 10;
}
int main() {
int x = 10;
fun (x, x);
cout << x;
return 0;
}
6. What is the scope of the variable declared in the user defined function?
7. How many minimum number of functions should be present in a C++ program for its execution?
8. Which of the following is the default return value of functions in C++?
9. When do we define the default values for a function?
10. Where should default parameters appear in a function prototype?
11. Which of the following feature is used in function overloading and function with default argument?
12. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int fun(int x = 0, int y = 0, int z){
return (x + y + z);
}
int main() {
cout << fun(10);
return 0;
}
13. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int fun(int = 0, int = 0); //define a function
int main() {
cout << fun(5);
return 0;
}
int fun(int x, int y){ //declare a function
return (x + y);
}
6 out of 9
1. The data elements in the structure are also known as …..
2. What will be used when terminating a structure?
3. What will happen when the structure is declared?
4. What will be the output of the following C++ code?
#include <iostream>
#include <string.h>
using namespace std;
int main() {
int student{
int num;
char name[25];
}
student stu; //structure object
stu.num = 123;
strcpy(stu.name, “john”);
cout << stu.num << “ “;
cout << stu.name << endl;
return 0;
}
5. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
struct Time{
int hours, minutes, seconds;
};
int toSeconds (Time now){
return 3600 * now.hours + 60 * now.minutes + now.seconds;
}
int main() {
Time t;
t.hours = 5;
t.minutes = 30;
t.seconds = 45;
cout << "Total seconds: " << toSeconds(t) << endl;
return 0;
}
6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
struct ShoeType{
string style;
double price;
};
ShoeType shoe1, shoe2;
shoe1.style = “Adidas”;
shoe1.price = 9.99;
cout << shoe1.style << "$" << shoe1.price;
shoe2 = shoe1;
shoe2.price = shoe2.price / 9;
cout << shoe2.style << "$" << shoe2.price;
return 0;
}
7. What will be the output of the following C++ code?
#include
using namespace std;
struct sec{
int a;
char b;
};
int main() {
sec s = {25, 50}; //ASCII 50 is ‘2’
sec *ps = &s;
cout < a << ',' < b ;
return 0;
}
8. Which of the following is a properly defined structure?
9. Which of the following accesses a variable in structure *b?
10. Which is the output?
struct Book{
string title;
string author;
int year;
int book_id;
};
int main(){
Book b1, b2;
b1.title = “Book1”;
b2 = b1;
cout << b2.title << endl;
return 0;
}
11. Which is the output?
struct Book{
string title;
string author;
int year;
int* book_id = new int;
};
int main(){
Book b1, b2;
*b1.book_id = 100;
b2 = b1;
cout << *b2.book_id << endl;
return 0;
}
12. Which is the output?
#include <iostream>
using namespace std;
struct Book{
int* book_id = new int;
};
int main() {
Book b1, b2;
*b1.book_id = 100;
b2 = b1;
cout << *b2.book_id << " ";
*b1.book_id = 500;
cout << *b2.book_id << endl;
return 0;
}
13. Which is the output?
#include <iostream>
using namespace std;
struct Book{
string title;
};
int main() {
Book* b1;
b1->title = “Book1”;
cout <title << endl;
return 0;
}
14. Which is the output?
#include <iostream>
using namespace std;
struct Book{
string title;
};
int main() {
Book* b1 = new Book[2];
Book* b2 = new Book[2];
b1[0].title = “Book11”;
b1[1].title = “Book12”;
b2[0].title = “Book21”;
b2[1].title = “Book22”;
b2=b1;
cout << b2[1].title << endl;
return 0;
}
7 out of 9
1. Which of the following correctly declares an array?
2. What is the index number of the last element of an array with 9 elements?
3. What is the correct definition of an array?
4. Which of the following gives the memory address of the first element in array?
5. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main() {
for (temp = 0; temp < 5; temp++){
result += array1[temp];
}
for (temp = 0; temp < 4; temp++){
result += array2[temp];
}
cout << result;
return 0;
}
6. Which of the following accesses the seventh element stored in array?
7. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a = 5, b = 10, c = 15;
int arr[3] = {&a, &b, &c};
cout << *arr[*arr[1] – 0];
return 0;
}
8. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
char str[5] = “ABC”;
cout << str[3];
cout << str;
return 0;
}
9. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
char array[] = {10, 20, 30};
cout << -2[array];
return 0;
}
10. Which header file is used to manipulate the string?
11. What is the difference between unsigned int length() and unsigned int size() of an array?
12. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() {
string str =”Steve jobs founded the apple”;
string str2 =”apple”;
unsigned found = str.find(str2);
if (found != string :: npos){
cout << found << "\n";
}
return 0;
}
13. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main() {
string str =”Steve jobs”;
unsigned long int found = str.find_first_of(“aeiou”);
while (found <= str.length())
{
str[found] = ‘*’;
found = str.find_first_of(“aeiou”, found + 1);
}
cout << str << "\n";
return 0;
}
8 out of 9
1. What does the following statement mean?
2. Which statement has the correct description of the following C++ declaration?
3. What will happen in the following C++ code snippet?
int a =100, b =200;
int *p = &a, *q = &b ;
p = q
4. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int a = 5, b = 10, c = 15;
int *arr[] = {&a, &b, &c};
cout << arr[1];
return 0;
}
5. Which answer decribes correctly a function that takes pointer to a float, a pointer to a pointer to a char and returns a pointer to a pointer to a integer?
6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
char arr[20];
int i;
for (i = 0; i < 10; i++){
*(arr + i) = 65 + i; //65 is ASCII ‘A’
}
*(arr + i) = ‘\0’;
cout << arr;
return 0;
}
7. What will be the output of the following C++ code?
#include
using namespace std;
int main() {
char str[] = “abcdefg”;
char str2[] = {‘a’,’b’,’c’,’d’};
char str3[] = {‘A’,’B’,’C’,’D’,0};
char str4[] = {65,66,67,0};
int num[] = {1,3,5,7,9};
cout << str << ' ';
cout << str[5] << ' ';
cout << str2 << ' ';
cout << str2[2] << ' ';
cout << str3 << ' ';
cout << str3[2] << ' ';
cout << str4 << ' ';
cout << str4[2] << ' ';
cout << num << ' ';
cout << num[1] << endl;
return 0;
}
8. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
char *ptr;
char str[] = “abcdefg”;
ptr = str;
ptr += 5;
cout << ptr;
return 0;
}
9. What is the meaning of the following declaration?
10. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int arr[] = {4, 5, 6, 7};
int *p = (arr + 1);
cout << *p;
return 0;
}
11. What will happen in the following C++ code snippet?
#include <iostream>
using namespace std;
int main() {
int arr[] = {4, 5, 6, 7};
int *p = (arr + 1);
cout << arr;
return 0;
}
12. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int numbers[5];
int *p;
p = numbers; *p = 10;
p++; *p = 20;
p = numbers[2]; *p = 30;
p = numbers + 3; *p = 40;
p = numbers; *(p + 4) = 50;
for (int n = 0; n < 5; n++){
cout << numbers[n] << ",";
}
return 0;
}
13. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int arr[] = {4, 5, 6, 7};
int *p = (arr + 1);
cout << *arr + 9;
return 0;
}
14. The void pointer can point to which type of objects?
15. When does the void pointer can be dereferenced?
16. What is the value of x after calling addOnetoX?
#include <iostream>
using namespace std;
void addOnetoX(int x) {
x = x + 1;
}
int main() {
int x = 100;
addOnetoX(x);
cout << x << endl;
return 0;
}
17. What is the value of x after calling addOnetoX?
#include <iostream>
using namespace std;
void addOnetoX(int*p) {
*p = *p + 1;
}
int main() {
int x = 100;
addOnetoX(&x);
cout << x << endl;
return 0;
}
9 out of 9