Retro C++ quiz #58
Given the following in C++:
int main() {
int arr[10][20]{};
auto x = arr[1,2] ;
}
Without checking the type of x is:
A. int
B. int*
C. Depends on standard version
D. The initialization is Ill-formed
Retro C++ quiz #58
Given the following in C++:
int main() {
int arr[10][20]{};
auto x = arr[1,2] ;
}
Without checking the type of x is:
A. int
B. int*
C. Depends on standard version
D. The initialization is Ill-formed
Retro C++ quiz #57
Given the following in C++:
#include <cstdint>
#include <limits>
int main() {
int64_t s=32;
int64_t x=std::numeric_limits<int32_t>::max();
1 << s; // A
1 + x; // B
}
Without checking, assuming LP64, which invokes undefined behavior:
A. Both
B. None
C. A
D. B
Retro C++ quiz #56
Given the following in C and C++ (assume correct header is included):
int main(void) {
int n = sizeof(0)["abcdefghij"];
printf("%d\n",n);
}
Without checking, assuming LP64, what’s the result:
C | C++
=========
A. 1 | 1
B. 101 | 101
C. 1 | 101
D. 101 | 1
Retro C++ quiz #55
Given the following in C++:
void f(int);
void f(short);
void f(long);
And the call to f() below:
void g(){
f(0u);
}
Assuming LP64, which f() is chosen:
A. f(int)
B. f(short)
C. f(long)
D. ambiguous can’t choose
#311 Given the following in C++
#include <iostream>
int f(int x) {
std::cout << x;
return x;
}
int main() {
[a=f(0),b=f(1)](){}();
}
Without checking, what is outputted?
A. 01
B. 10
C. Could be A or B
Retro C++ quiz #54
Given the following in C and C++:
void f(void);
void f() {
const const int x=1;
}
This is, without checking:
A. Valid C99 and C++
B. Valid C99
C. Valid C++
D. Neither Valid C99 or C++
#310 Given the following in C++
struct A {
const int :1; // Well-formed?
};
Without checking:
A. Yes
B. No
Retro C++ quiz #53
Given the following in C++:
#include <iostream>
struct A {
operator int() {return 1;}
};
bool operator==(A, int){return 0;}
What is the result of:
int main() {
std::cout <<(1 == A{})<<"\n";
}
A. 1
B. 0
C. Ill-formed
D. Depends on standard version
Retro C++ quiz #52
Given the following C code
#include <stdio.h>
int main(void) {
for (size_t i=0;i<6;++i) {
typedef int VLA[i++];
printf("%zu",i);
}
}
W/o checking what is the output?
A. 012345
B. 135
C. ¯\_(ツ)_/¯ undefined behavior
D. Varies on standard version
Retro C++ quiz #51
Given the following in C++:
struct A {
virtual void f() = +0;
};
Without checking, is this:
A. Well-formed
B. Ill-formed (requires a diagnostic)
C. Depends on the standard version