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

Assignment Format

The document contains the answers to 5 questions about C++ code snippets. Each answer includes the code, which assigns a large integer to an int and then to a short variable, resulting in overflow. It also includes sample output. The answers are largely repetitive, as each tests the same code and demonstrates overflow by assigning an integer larger than a short can hold to that variable.

Uploaded by

david jhon
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)
36 views

Assignment Format

The document contains the answers to 5 questions about C++ code snippets. Each answer includes the code, which assigns a large integer to an int and then to a short variable, resulting in overflow. It also includes sample output. The answers are largely repetitive, as each tests the same code and demonstrates overflow by assigning an integer larger than a short can hold to that variable.

Uploaded by

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

ASSIGNMENT 02

[Document subtitle]
Contents
Ans1:......................................................................................................................................................2
Ans2:......................................................................................................................................................2
Ans3:......................................................................................................................................................3
Ans4:......................................................................................................................................................4
Ans5:......................................................................................................................................................5
Ans1:
Code
#include <iostream>
using namespace std;
int a = 10;
int main() {
int big = 980000;
short small;
cout << "big=" << big << endl;
small = big; //don't do this
cout << "small=" << small << endl;
cin >> a;
return 0;
}

Output:

Jlskdjflkasjdlfjsd ljlkjlkjlkjl lkjlkjlk

Figure 1: Output of Question 1

Ans2:
Code
#include <iostream>
using namespace std;
int a = 10;
int main() {
int big = 980000;
short small;
cout << "big=" << big << endl;
small = big; //don't do this
cout << "small=" << small << endl;
cin >> a;
return 0;
}

Output:

Jlskdjflkasjdlfjsd ljlkjlkjlkjl lkjlkjlk

Figure 2: Output of Question 1

Ans3:
Code
#include <iostream>
using namespace std;
int a = 10;
int main() {
int big = 980000;
short small;
cout << "big=" << big << endl;
small = big; //don't do this
cout << "small=" << small << endl;
cin >> a;
return 0;
}

Output:

Jlskdjflkasjdlfjsd ljlkjlkjlkjl lkjlkjlk


Figure 3: Output of Question 1

Ans4:
Code
#include <iostream>
using namespace std;
int a = 10;
int main() {
int big = 980000;
short small;
cout << "big=" << big << endl;
small = big; //don't do this
cout << "small=" << small << endl;
cin >> a;
return 0;
}

Output:

Jlskdjflkasjdlfjsd ljlkjlkjlkjl lkjlkjlk


Figure 4: Output of Question 1

Ans5:
Code
#include <iostream>
using namespace std;
int a = 10;
int main() {
int big = 980000;
short small;
cout << "big=" << big << endl;
small = big; //don't do this
cout << "small=" << small << endl;
cin >> a;
return 0;
}

Output:

Jlskdjflkasjdlfjsd ljlkjlkjlkjl lkjlkjlk


Figure 5: Output of Question 1

You might also like