What would these codes print: 1. } 2. } 3. } 4. } 5. } 6. } 7. } 8. #include <io
ID: 3793338 • Letter: W
Question
What would these codes print:
1.
}
2.
}
3.
}
4.
}
5.
}
6.
}
7.
}
8.
#include <iostream> int main() { int a[5] = {4, 2, 0, -1, -3}; int *a_ptr = a; while (*a_ptr != 0) { std::cout << *a_ptr << std::endl; a_ptr += *a_ptr; }}
2.
#include <iostream> int main() { int a[7] = {0, 1, 1, 1, 1, 1, 0}; int *a_ptr = a; while (*(++a_ptr) != 0) { *a_ptr += *(a_ptr-1); std::cout << *a_ptr << std::endl; }}
3.
#include <iostream> int main() { int a = 1; int b = 2; int c = 3; int *a_ptr = &c; int *b_ptr = &b; int *c_ptr = &a; *a_ptr = 3; *b_ptr = 2; *c_ptr = 1; std::cout << a << std::endl; std::cout << b << std::endl; std::cout << c << std::endl;}
4.
#include <iostream> int main() { int a[6] = {0, 2, 3, 4, 5, 0}; int *a_ptr = a; while (*(++a_ptr) != 0) (*a_ptr)--; for (int i=0; i<5; i++) std::cout << a[i] << std::endl;}
5.
#include <iostream> int main() { int a[6] = {1, 2, 4, 6, 10, 0}; for (int *a_ptr = a; *a_ptr != 0; a_ptr++) std::cout << *(a_ptr+1) << ' ' << *a_ptr + 1 << std::endl;}
6.
#include <iostream> int main() { int a = 1, b = 1, c = 1; int *a_ptr = &a, *b_ptr = &b, *c_ptr = &c; for (int i=0; i<10; i++) { std::cout << *a_ptr << std::endl; *c_ptr = *a_ptr + *b_ptr; *a_ptr = *b_ptr; *b_ptr = *c_ptr;}
7.
#include <iostream> int main() { int a[5] = {3, 2, 1, 0, 4}; int *a_ptr[5]; for (int i=0; i<5; i++) a_ptr[i] = a+a[i]; for (int i=0; i<5; i++) std::cout << *a_ptr[i] << std::endl;}
8.
#include <iostream> int main() { int a[6] = {0, 1, 3, 7, 15, 0}; int *a_ptr = a; while ( (*(++a_ptr))++ ); for (int i=0; i<5; i++) std::cout << a[i] << std::endl; }Explanation / Answer
The following are the outputs of the given codes
output for 1)
4
-3
2
-1
output for 2)
output for 3)
output for 4)
output for 5)
output for 6)
output for 7)
output for 8)
0
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.