- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Size of an Array
#include <iostream>
using std::cout;
using std::endl;
int main()
{
int a[5] = { 0, 2, 4, 6, 8 };
cout << sizeof(a[0]) << endl;
cout << sizeof(a) << endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Character Array
#include <iostream>
using std::endl;
using std::cout;
int main()
{
char s[] = "NCNU";
char horse[] = "~/-\\^";
char c = horse[4];
char* p = &horse[4];
cout << sizeof (s) << c << (p - horse) << endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Pointer
#include <iostream>
using std::cout;
using std::endl;
int main()
{
int n = 2017;
int* p = &n;
cout << (*p) ++ << endl;
cout << (*p) << endl;
cout << ++ (*p) << endl;
return 0;
}