ProgrammingModerateTCS NQT · Wipro
With int a[3], *p = a; which statement fails to compile?
- A. p = a + 2;
- B. a++;
- C. p++;
- D. *(a + 1) = 5;
Correct answer: B. a++;
An array name converts to a pointer value in expressions, but the array itself is not a modifiable lvalue, so a++ is rejected. p is an ordinary pointer variable, and a + 1 is a fine expression to dereference.
More C Programming questions
- Assume 4-byte int. What is printed? c struct Msg { int len; char data[]; }; struct Msg m = malloc(sizeof m + 10); printf("%zu", sizeof m);
- What is printed? c printf("%zu %zu", sizeof("ab" "cd"), strlen("ab0cd"));
- What is printed? c int n = printf("%d", printf("%s", "abc")); printf(" %d", n);
- What is printed? c int f(int n, int b) { return n < b ? 1 : 1 + f(n / b, b); } int main(void) { printf("%d %d %d", f(1000, 2), f(1000…
- What is printed? c const char s = "education"; int v = 0, o = 0; for (; s; s++) switch (s) { case 'a': case 'e': case 'i': case 'o': case…
- Which of these functions return a pointer that is still valid to read after the function returns? c char f1(void) { char s[] = "hi"…