#1 Data Type && Conditions
#1 Data Type && Conditions
Questions
1- What will happen if we divide by zero?
a. Time limit.
b. Memory limit.
c. Runtime error.
d. Stack overflow.
6- what is the size of (short,int, long long ,float ,double ,char ,bool ,string)
10- Given two numbers a and b, your task is to print the remainder of
division a by b , Note: without using Modulo (%) .
example a=9 b=4 output: 1
a. 100000
b. 10000000000
c. Run time error.
d. Overflow
2)
#include<iostream>
using namespace std;
int main() {
int x = 1000000000;
int y = x * 2;
cout << x + y / 2;
}
3)
ICPC Assuit Community
#include <iostream>
using namespace std;
int main() {
int a = 0, b;
b = (a = 50) + 10;
cout << a << "$" << b;
return 0;
}
4)
#include<iostream>
using namespace std;
int main() {
int x = 10, y = 20;
if (x++ || y++) {
y += 5;
} else if (x == 10) {
x -= 5;
}
if (y == 20) {
y = x;
}
if (x++ && y++) {
x += 5;
}
cout << x << " " << y << endl;
}
ICPC Assuit Community
6)
#include <iostream>
using namespace std;
int main() {
int a = b = c = 0;
cout << a << "*" << b << "*" << c;
return 0;
}
7)
#include <iostream>
int main() {
if (std::cout << "hello")
std::cout << " world";
else
std::cout << " else part";
return 0;
}
ICPC Assuit Community
9)
#include <iostream>
using namespace std;
int main() {
int a = 1;
switch (a) {
case 1:
cout << "One";
case 2:
cout << "Two";
case 3:
cout << "Three";
default:
cout << "Default";
}
return 0;
}
a. One
b. Compilation Error
c. Default
d. OneTwoThreeDefault
10)
ICPC Assuit Community
#include <iostream>
using namespace std;
int main() {
int a;
a = 5;
if (++a * 5 <= 25) {
cout << "Hello";
} else {
cout << "Bye";
}
}
a. Hello
b. Bye
c. Undefined
d. Compilation Error
11)
#include <iostream>
using namespace std;
int main() {
int x = 5;
if (x++ == 5)
cout << "Five" << endl;
else if (++x == 6)
cout << "Six" << endl;
return 0;
}
a. FiveSix
b. Five
c. Six
d. None of these
12)
ICPC Assuit Community
#include <iostream>
using namespace std;
int main() {
int a;
cout << "Size of int is: " << sizeof(a);
}
13)
#include <iostream>
using namespace std;
int main() {
char a;
a = 'R';
cout << " Size of char is: " << sizeof(a) << endl;
cout << " Value of a is: " << a;
}
14)
#include <iostream>
using namespace std;
int main() {
bool a;
cout << " Size of bool is: " << sizeof(a) << endl;
cout << " Value of a is: " << a;
}
ICPC Assuit Community
15)
#include <iostream>
using namespace std;
int main() {
int x = 5,y=5;
x = y++;
y = ++x;
x *= y;
cout << x << " " << y;
}
16)
// logical operators
#include <iostream>
using namespace std;
int main() {
cout << true << endl;
cout << false << endl;
cout << (true || false) << endl;
cout << (true && false) << endl;
return 0;
}
17)
ICPC Assuit Community
// relational operators.
#include <iostream>
using namespace std;
int main() {
cout << (5 == 10) << endl;
cout << (10 > 5) << endl;
cout << ((5 >= 1) && (5 <= 10)) << endl;
return 0;
}
18)
#include <iostream>
using namespace std;
int main() {
char ch = 'a';
cout << int(ch); return 0;
}
19)
#include <iostream>
using namespace std;
int main() {
char ch = 'A';
cout << ++ch;
return 0;
}
20)
ICPC Assuit Community
#include <iostream>
using namespace std;
int main() {
char ch = 'A';
cout << ch + 32;
return 0;
}
21)
#include <iostream>
using namespace std;
int main() {
char ch = 'N';
cout << char(ch + 32);
return 0;
}
22)
ICPC Assuit Community
#include <iostream>
using namespace std;
int main() {
int x = 2;
if (!x == 0) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
23)
#include <iostream>
using namespace std;
int main() {
int x = 0;
if (!x != 0 && x == 1 || !x) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
ICPC Assuit Community
25)
#include <iostream>
using namespace std;
int main() {
bool ok = 0;
if (!!(ok) && ok != !ok) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
26)
ICPC Assuit Community
#include <iostream>
using namespace std;
int main() {
int x = 0, y = 0;
if (!(x++ == 0 || ++y == 0)) {
x++;
} else if (++x == y++) {
y++;
}
if (x > y)
y = x++;
cout << x << " " << y;
return 0;}
27)
#include <iostream>
using namespace std;
int main() {
int x = 1, y = 2, mx = 0, mn = 100;
if (x > mx)
mx = x;
else if (x < mn)
mn = x;
if (y > mx)
mx = y;
else if (y < mn)
mn = y;
cout << mx << " " << mn;}
ICPC Assuit Community
29)
#include <iostream>
using namespace std;
int main() {
char c = '0';
int x = c;
if (x % 2) {
cout << "Even";
} else {
cout << "Odd";
}
}
30)
ICPC Assuit Community
#include <iostream>
using namespace std;
int main() {
char c = 67;
if (c == 'c') {
cout << "Yes";
} else {
cout << "No";
}
}
31)
#include <iostream>
using namespace std;
int main() {
int x = 15, y = 2;
if (x++ % 2 == y % 2)
x++;
else if (!(x % 2 == y % 2))
++y;
if (x % y)
cout << "Yes";
else
cout << "No";
}
32)
ICPC Assuit Community
#include <iostream>
using namespace std;
int main() {
int x = 70, n1 = 1, n2 = 100, n3 = 50;
if (x >= n1 && x <= n2) {
if (x >= n1 && x <= n2)
cout << "Yes";
} else {
cout << "No";
}
}
33)
#include <iostream>
using namespace std;
int main() {
int x, y, z;
x = 0,y = 1,z = 2;
if (x < y < z == x) {
cout << "True";
} else {
cout << "False";
}
}
ICPC Assuit Community
Answers
1. Runtime error
2. (int)1e5
3. 1
4. Explain
5. Int : 231 -1 ,long long : 263-1
6.
short :2
int :4
long long :8
float:4
double:8
char:1
bool:1
string :1byte for each character in it
7. 4 bytes
8. 4 bytes
9. 8
10. The solution is on GitHub
11.
1) d.Overflow
2) a. 2000000000
3) 50$60
4) 17 26
5) Right choice
ICPC Assuit Community
8) 120
9) d. OneTwoThreeDefault
10) b. Bye
11) b. Five
12) Size of int is: 4
13) Size of char is: 1
Value of a is: R
14) Size of bool is: 1
15) 36 6
16) 1
0
1
0
17) 0
1
1
18) 97
19) B
ICPC Assuit Community