C/C++ Based Test: 27 Question 35 Marks: Q1 Find The Output Assume Size of Int Is 4 Byte
C/C++ Based Test: 27 Question 35 Marks: Q1 Find The Output Assume Size of Int Is 4 Byte
C/C++ Based Test: 27 Question 35 Marks: Q1 Find The Output Assume Size of Int Is 4 Byte
class base {
int arr[10];
};
int main(void)
return 0;
A. 20
B. 40
C. 80
D. 120
E. None of these
Answer: (B)
Q2
int main()
{
derived object;
return 0;
}
a) DconDDest
b) DconDDestBConBDest
c) BConDConDDestBDest
d) BConDConBDesDDest
Answer: (c)
class Singleton
{
private:
static Singleton* instance;
Singleton();
public:
static Singleton* getInstance();
};
Singleton* Singleton::instance = 0;
Singleton* Singleton::getInstance()
{
if (instance == 0)
{
instance = new Singleton();
}
return instance;
}
Singleton::Singleton()
{}
int main()
{
Singleton* one = Singleton::getInstance();
Singleton* two = Singleton::getInstance();
if(one == two)
std::cout<<"Both pointers hold same object";
else
std::cout<<"They don't hold same object";
return 0;
}
a) Both pointers hold same object
b) They don't hold same object
c) Compilation Error
d) Exception occurred
public:
C();
};
a) Yes
b) No
Answer: (A)
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void print_square(int i)
{
cout<<i*i<<endl;
}
int main()
{
vector<int> v;
// vector gets filled
for_each(v.begin(), v.end(), print_square);
return 0;
}
a) Yes
b) No
c) Depends on Compiler
Answer: (A)
7. Is this valid C++ 11 program & get compiled without any error?
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
vector<int> v;
// vector gets filled
for_each(v.begin(), v.end(),
[](int i) { cout<<i*i<<endl; } );
return 0;
}
a) Yes
b) No
Answer: (A)
8. If you use either Telnet or FTP, which is the highest layer you are using
to transmit data?
1. Application
2. Presentation
3. Session
4. Transport
Answer: (A)
9. Pushing an element into stack already having five elements and stack
size of 5, then stack becomes
a) Overflow
b) Crash
c) Underflow
d) User flow
Answer: (A)
10.
What is the value of the postfix expression 6 3 2 4 + – *:
a) 1
b) 40
c) 74
d) -18
Answer: (A)
11.
a) 3 1
b) 3 2 1
c) 3
d) Infinite Loop
Answer: (D) Infinite Loop
12
a) 0
b) 25
c) 26
d) 1
Answer: (B)
13.
#include <iostream>
using namespace std;
int a = 2;
int fun(int *a) {
::a *= *a;
cout<< ::a <<endl;
return *a; }
int main() {
int a = 9;
int&x = ::a;
::a += fun(&x);
cout<< x; }
Output:
4
14.
#include <iostream>
using namespace std;
int main() {
char *A[] = { "abcx", "dbba", "cccc"};
char var = *(A+1) - *A+1;
cout<< (*A + var); }
Output: bba
Output:
Constructor is executed
Destructor is executed
16.
#include <iostream>
class X {
private:
static const int a = 76;
public:
static int getA() { return a; } };
int main() {
cout<<X::getA()<<endl;
return 0; }
Output: 76
17. #include<stdlib.h>
#include<iostream>
using namespace std;
class Test {
public:
void* operator new(size_t size);
void operator delete(void*);
Test() { cout<<"\n Constructor called"; }
~Test() { cout<<"\n Destructor called"; }
};
void* Test::operator new(size_t size)
{
cout<<"\n new called";
void *storage = malloc(size);
return storage;
}
void Test::operator delete(void *p )
{
cout<<"\n delete called";
free(p);
}
int main()
{
Test *m = new Test();
delete m;
return 0;
}
Output: new called
Constructor called
Destructor called
delete called
18.
{char ch;
int I;
scanf(“%c”, &i);
scanf(“%d”,&ch);
printf(“%c””%d”,ch,i);
return 0;}
a) No error
b) Error: Suspicious char to inversion in scanf()
c) None
d) Error: We may get input for second scanf() statement
Output: A No error
19.
Void my_recursive_function(int n)
{if(n==0)return;
printf(“%d”,n); }
int main(){
my_recursive_function(10);
return 0;}
a) 10 9 8 …1 0
b) 10 9 8 …1
c) 1
d) 10
Output: d) 10
The Internet Protocol also provides basic instructions for transferring packets
between devices. However, it does not actually establish the connection or define
the ordering of the packets transmitted. These aspects are handled by the
Transmission Control Protocol, which works in conjunction with the Internet
Protocol to transfer data between systems on the Internet. For this reason,
connections between Internet-connected systems are often called "TCP/IP"
connections.
OSI: The OSI (Open Systems Interconnection) model was created by the ISO to help
standardize communication between computer systems. It divides communications
into seven different layers, which each include multiple hardware standards, protocols,
or other types of services.
The seven layers of the OSI model include:
The best way to explain how the OSI model works is to use a real life example. In the
following illustration, a computer is using a wireless connection to access a secure
website.
The communications stack begins with the (1) physical layer. This may be the
computer's Wi-Fi card, which transmits data using the IEEE 802.11n standard. Next,
the (2) data link layer might involve connecting to a router via DHCP. This would
provide the system with an IP address, which is part of the (3) network layer. Once the
computer has an IP address, it can connect to the Internet via the TCP protocol, which
is the (4) transport layer. The system may then establish a NetBIOS session, which
creates the (5) session layer. If a secure connection is established, the (6) presentation
layer may involve an SSL connection. Finally, the (7) application layer consists of the
HTTP connection to the website.
The OSI model provides a helpful overview of the way computer systems
communicate with each other. Software developers often use this model when writing
software that requires networking or Internet support. Instead of recreating the
communications stack from scratch, software developers only need to include
functions for the specific OSI layer(s) their programs use
24. There is a class which contains two integers as private members. There
are two member functions (public) defined on it, one to add the two
integers and another to subtract the two integers. Ravi wants to add a new
functionality, which enables multiplication of the two numbers. Which one
of the following options he should adopt?
a) He should define a third member function (public) which multiplies the two
numbers.
b) He should define member functions (public) to return the value of both the
integers and then multiply them in his code. By returning the values, he can in
future do any operation on them giving extensibility to the code.
c) He should define a third member function (private) which multiplies the
two numbers.
d) He should define member functions (private) to return the value of both
the integers and then multiply them in his code. By returning the values, he
can in future do any operation on them giving extensibility to the code.
Q 27. Input a matrix (M*N) and print the row contain maximum sum (5
marks)
Example:
1 2 3 ==6(sum of element)
4 5 6 ==15
7 8 9 ==23
#include <bits/stdc++.h>
// with maximum
int sum = 0;
// calculate sum of row
sum += mat[i][j];
// current sum
maxSum = sum;
// store index
idx = i;
// return result
return res;
}
// Driver code
int main()
int mat[N][N] = {
{ 1, 2, 3, 4, 5 },
{ 5, 3, 1, 4, 2 },
{ 5, 6, 7, 8, 9 },
{ 0, 6, 3, 4, 12 },
{ 9, 7, 12, 4, 3 },
};
cout << "Row " << ans.first + 1 << " has max sum "
<< ans.second;
return 0;