0% found this document useful (0 votes)
35 views

#1 Data Type && Conditions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

#1 Data Type && Conditions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

ICPC Assuit Community

Newcomers (Datatypes & Conditions)

Questions
1- What will happen if we divide by zero?
a. Time limit.
b. Memory limit.
c. Runtime error.
d. Stack overflow.

2- What is equal to 100000?


a. 10000000000 - 100000.
b. 10000000000 / 10000.
c. (int)1e5.
d. 100000- 200000.

3- What is the result of dividing 3/2 in C++?


a. 1
b. 1.5
c. 2
d. A run-time error.
e. none of the above
4- what is the difference between x++ and ++x ?

5- how to calculate the max number in (int - long long)

6- what is the size of (short,int, long long ,float ,double ,char ,bool ,string)

7- What is the size of “unsigned int”?


a. 2 bytes
b. 4 bytes
c. 8 bytes
d. 5 byte

8- What is the size of “signed int”?


ICPC Assuit Community

Newcomers (Datatypes & Conditions)


a. 2 bytes
b. 4 bytes
c. 8 bytes
d. 5 byte

9- What is The number of bits in char data type?

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

11- What is the output ?


ICPC Assuit Community

Newcomers (Datatypes & Conditions)


1)
#include<iostream>
using namespace std;
int main() {
int x = 100000;
int y;
y = x;
x *= y;
cout << x;
}

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;
}

a. 2000000000. c. Run time error.


b. 1000000000. d. Overflow

3)
ICPC Assuit Community

Newcomers (Datatypes & Conditions)

#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

Newcomers (Datatypes & Conditions)


5)
#include<iostream>
using namespace std;
int main() {
int x = 3;
if (4 > x > 2) {
cout << "Well Done";
} else {
cout << "Right choice";
}
}

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

Newcomers (Datatypes & Conditions)


8)
#include <iostream>
using namespace std;
int main() {
char a = 30, b = 40, c = 10;
char d = (a * b) / c;
cout << int(d);
return 0;

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

Newcomers (Datatypes & Conditions)

#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

Newcomers (Datatypes & Conditions)

#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

Newcomers (Datatypes & Conditions)

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

Newcomers (Datatypes & Conditions)

// 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

Newcomers (Datatypes & Conditions)

#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

Newcomers (Datatypes & Conditions)

#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

Newcomers (Datatypes & Conditions)


24)
#include <iostream>
using namespace std;
int main() {
int x = 0, y = 1;
if (++x && --y) {
cout << x << " " << y;
} else {
cout << x++ << " " << --y;
}
return 0;
}

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

Newcomers (Datatypes & Conditions)

#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

Newcomers (Datatypes & Conditions)


28)
#include <iostream>
using namespace std;
int main() {
int x = 0, y = 0;
if (x && ++y) {
cout << "YES ";
} else if (++x || y++) {
cout << "NO ";
}
cout << x << " " << y;
}

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

Newcomers (Datatypes & Conditions)

#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

Newcomers (Datatypes & Conditions)

#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

Newcomers (Datatypes & Conditions)

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

Newcomers (Datatypes & Conditions)


6) Compilation error (the correct : int a,b,c ;
a=b=c=0;)
7) hello world
Explanation: Since std::cout<<"hello" returns a reference to
std::cout, therefore, the condition gets true, and the if block is
executed.

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

Value of a is: 0 or Value of a is: 0 (garbage)

15) 36 6
16) 1
0
1
0
17) 0
1
1
18) 97
19) B
ICPC Assuit Community

Newcomers (Datatypes & Conditions)


20) 97
21) n
22) Yes
23) Yes
24) 1 -1
25) No
26) 32
27) 2 100
28) No 1 0
29) Odd
30) No
31) No
32) Yes
33) False

You might also like