ProgrammingModerateProduct company OA
What does `_Static_assert(sizeof(long) >= 8, "need 64-bit long");` do in C11?
- A. Checks the condition at run time and aborts the program if it fails
- B. Stops compilation with the given message if the condition is false on this platform
- C. Prints the message as a warning but continues compiling
- D. Changes long to 64 bits if it is smaller
Correct answer: B. Stops compilation with the given message if the condition is false on this platform
_Static_assert evaluates a constant expression at compile time and makes the compilation fail with the message if it is false. It costs nothing at run time; assert from <assert.h> is the run-time check.
More C Programming questions
- What is printed? c int i = 0, s = 0; do { if (++i == 3) continue; if (i == 5) break; s += i; } while (i < 10); printf("%d %d", s, i);
- What is printed? c struct N { int v; struct N nx; }; void del(struct N h, int x) { while (h) { if ((h)->v == x) h = (h)->nx; else h =…
- What is printed? c int rot(const char a, const char b) { char buf[32]; if (strlen(a) != strlen(b)) return 0; strcpy(buf, a); strcat(buf…
- What is printed? c int alt(unsigned x) { unsigned y = x ^ (x >> 1); return (y & (y + 1)) == 0; } int main(void) { printf("%d%d%d", alt(5)…
- What is printed? c struct In { int a[2]; }; struct Out { struct In in[2]; int k; } o = {{{{1, 2}}, {{3, 4}}}, 5}; printf("%d %d"…
- What is printed? c struct In { int a[2]; }; struct Out { struct In in[2]; int k; } q = {1, 2, 3, 4, 5}; printf("%d %d", q.in[1].a[1], q.k);