Question

What is the output of the following code snippet? (If there is some kind of syntax...

What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice)

1.

       int fly = 5;

int x;

       if (fly-- > 5)

              x = 5;

       else

              x = 2;

       if (x++ > 3)

              cout << x;

       cout << fly << endl;

2.

  int i = 0;

       bool b = i == 0 || i++ > 0;

       if (!b)

              cout << i << endl;

       else

              cout << b << " " << i << endl;

3.

int num = 10;
    char c = num;
    c++;
    num++;
    if (num == c)
        num-=5;
    else
        num-=9;
    cout << num << endl;

4.

  1. int quiz = 100;
  2. int t = quiz;
  3. if (quiz >= t)
  4.    quiz -= 89;
  5. else
  6.    t += 10;
  7. cout<< quiz << t;

5.

int i = 0;
    float f = 1.1;

    if (i++ > --f)
    {
        i = f + 2;
    }
    else if ( ++i > --f)
    {
        i = 3 - f;
    }
    else
    {
        i = f * 3;
    }

    cout << i << " " << f << endl;

0 0
Add a comment Improve this question Transcribed image text
Answer #1
nswer:
1.
int fly = 5;
int x;
if (fly-- > 5)
    x = 5;
else
    x = 2;
if (x++ > 3)
    cout << x;
cout << fly << endl;

Output:
4

===============================

2.
int i = 0;
bool b = i == 0 || i++ > 0;
if (!b)
    cout << i << endl;
else
    cout << b << " " << i << endl;

Output:
1 0

===============================

3.
int num = 10;
char c = num;
c++;
num++;
if (num == c)
    num-=5;
else
    num-=9;
cout << num << endl;

Output:
6

===============================

4.
int quiz = 100;
int t = quiz;
if (quiz >= t)
   quiz -= 89;
else
   t += 10;
cout<< quiz << t;

Output:
11100

===============================

5.
int i = 0;
float f = 1.1;
if (i++ > --f)
{
    i = f + 2;
}
else if ( ++i > --f)
{
    i = 3 - f;
}
else
{
    i = f * 3;
}
cout << i << " " << f << endl;

Output:
3 -0.9
Add a comment
Know the answer?
Add Answer to:
What is the output of the following code snippet? (If there is some kind of syntax...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 51. What is the output of the following code snippet? int number = 0; int ptr_num...

    51. What is the output of the following code snippet? int number = 0; int ptr_num -&number ptr_num 60; number-80 cout < "ptr num << endl b, 60 c. 80 d. the address of number Answer 52. What is the output of the following code snippet? double num-0.0; double* ptr = &num; num = 15.0; ptr ptr 15.0 cout << num <<"ptr <<endl; a. 15 15 b. 15 30 С. 30 15 d. 30 30 Answer: 53. What is the...

  • QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...

    QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...

  • Example (4) Trace the following program and find the output >> SOURCE CODE #include <iostream.h> int...

    Example (4) Trace the following program and find the output >> SOURCE CODE #include <iostream.h> int main0 // define two integers int x-3; int y = 4; //print out a message telling which is bigger if (x >y) i cout << "x is bigger than y" << endl: else cout << "x is smaller than y" << endl; return 0; Example (5) Write a C++ program that takes from the user a number in SR (Saudi Riyal) then the program...

  • what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...

    what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...

  • CGALLENE 4.2: More syntax errors. ACTIVITY Each cout statement has a syntax error. Type the first...

    CGALLENE 4.2: More syntax errors. ACTIVITY Each cout statement has a syntax error. Type the first cout statement, and press Run to observe the error message. Fix the error, and run again. Repeat for the second, then third, cout statement cout << "Num: "<< songnum << endl; cout << int songNum << endl; cout << songNum " songs" << endl; Note: These activities may test code with different test values. This activity will perform two tests: the first with songNum-5,...

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • Consider the following C++code snippet and what is the output of this program? # include<iostream> using...

    Consider the following C++code snippet and what is the output of this program? # include<iostream> using namespace std; void arraySome (int[), int, int); int main () const int arraysize = 10; int a[arraysize]-1,2,3,4,5, 6,7,8,9,10 cout << "The values in the array are:" << endl; arraySome (a, 0, arraySize) cout<< endl; system ("pause") return 0; void arraySome (int b[], int current, int size) if (current< size) arraySome (b, current+1, size); cout << b[current] <<""; a) Print the array values b) Double...

  • 5. What is the output of the following section of a program int a[10] = {2,5,1,6,x,7,0,3,y,8};       ...

    5. What is the output of the following section of a program int a[10] = {2,5,1,6,x,7,0,3,y,8};        for(int i=0;i<9;i++)      a[i]=a[i+1]; for(int i=0;i<8;i++)      cout<<a[i]<<” “; cout<<endl; 6. What will be shown on the output screen after following statements are executed? char a[ ]="I have a part time job"; int c=x, i=0 while(a[i]!=’\0’){      if(a[i]==' '){           c++;           cout<<endl;      }      else           cout<<a[i];      i++; } cout<<c<<endl; 7. After following statements are executed, what are the outputs char a[ ]= "Fresno City College";        for (i...

  • /// c ++ question plz help me fix this not a new code and explain to...

    /// c ++ question plz help me fix this not a new code and explain to me plz /// Write a function to verify the format of an email address: bool VeryifyEmail(char email[ ]); Do NOT parse the email array once character at a time. Use cstring functions to do most of the work. Take a look at the available cstring and string class functions on cplusplus website. Use a two dimensional array to store the acceptable top domain names:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT