ProgrammingModerateTCS NQT · Wipro
Which of the following is NOT allowed in C?
- A. Assigning one struct to another of the same type with =
- B. Assigning one array to another with =
- C. Passing a struct that contains an array by value
- D. Returning a struct from a function
Correct answer: B. Assigning one array to another with =
An array name is not a modifiable lvalue, so a = b; between arrays does not compile; you must use memcpy or a loop. Structs, even ones containing arrays, can be assigned, returned and passed by value, which copies the whole thing.
More C Programming questions
- What is printed? c int cnt(int n, int last) { if (n == 0) return 1; return cnt(n - 1, 0) + (last ? 0 : cnt(n - 1, 1)); } int main(void) {…
- On a two's-complement machine, what is printed? c int a = 5; printf("%d %d %d", !a, ~a & 0xF, !!a + !~-1);
- What is printed? c const char s = "a1b22c333"; int sum = 0, cur = 0; for (; s; s++) { if (s >= '0' && s <= '9') cur = cur 10 + (s - '0')…
- What is printed? c typedef int (Op)(int); int twice(int x) { return 2 x; } int plus3(int x) { return x + 3; } int apply(Op f, Op g, int x)…
- What is printed? c for (int k = 0; k < 3; k++) { static int s[3]; int a[3] = {0}; s[k] = a[k] = k + 1; printf("%d%d ", s[0] + s[1] + s[2]…
- Assume ASCII. What is printed? c const char s = "pointer"; printf("%c%c%c", s + 1, s[s - 'o' + 2], (s + strlen(s) - 1) - 1);